lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

HI all,
I have a question regarding to passing pointer between Lua and C/C++.
Hope any Lua expert can give me a hand and any reference point!!
I want to do something like that.
(I use tolua to bind my C/C++ code)
In C/C++ code.
Object *o = new Object();
... Do something with this Object,
Push o (address) to lua stack
Run Lua script(s), which will pick up this pointer,  and continue do something (AI logic, mainly I intend to script entire state machine in lua), so that C/C++ code get the update right away.
It does not have to be exactly this way, but I want to figure out if it is possible to pass any reference to lua from native code, run the script(s) for some logic, and update this reference in lua script.  Any other ideas are very welcome.
I know I should push some kind of tag or use Userdata thing, but I was not able to find any good examples of using Userdata in Lua page.
Once of the reason I want to try this idea, is performance. I just simply want to prevent doing "pass by value" as much as possible.
Sorry for the newbie question, and thank you very much for the help.

Post your free ad now! Yahoo! Canada Personals