[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: references ?
- From: Reyn Vlietstra <reyn@...>
- Date: 14 Oct 2003 15:02:53 +0200
Hi.
I'v read through the archives and I just want to make
sure about something.
I create a table(object) with the C api by calling
a lua function:
myObject::new(ptr)
the ptr is so I can refer back to the actual C object.
That function then returns a table, which is then
access able in C at the top of the stack.
I need the object to be created through lua, so I just
write a simple function in C that would call itself
createObject() in lua.
So, thus far, things look like this:
-----------------------------------------------------------------------
Lua C
--- ---
x=CreateObject("objectname")-> cObject::LCreateObject()
|
v
cObject::cObject("luaobjectname")
which leaves a table on the top
of the stack, which LCreateObject()
then returns, and also puts the object
in a 'database'.
x now refers to
the created object.
-----------------------------------------------------------------------
Now some event happens, which causes the C side to want to call a
predefined function of x, then obviously we need to find the lua
object.
The way I have been doing this, is by keeping the object in a table
"allObject={}" so that I can find the object by using the pointer of
the C++ object as key, and getting the correct table back as value,
at which point I can then call the predefined function, but this lookup
is slow, and storing the object in my 'database' and a lua table
shouldnt be necessary.
The things I'v read on the mailing list suggest that there isn't a
way for the C++ object to 'remember' what lua table is associated
with it, and it needs to be stored in some table or the REGISTRY.
I'v tried using lua_gettop() to find the index of the object and then
using that index to 'recall' the object to the top of the stack, but
that doesnt work.
I know about luaBind and toLua, I just really want to understand
how this is done.
Thanks.
--
Reyn Vlietstra.