lua-users home
lua-l archive

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


A quick question: if I lock an object with
ref=lua_ref(L, 1), and then unlock it with lua_ref(L,
ref), is 'ref' still a valid Lua object? Meaning, if I
unlock an object from C++, will the reference stay
valid as long as Lua continues to hold the object, or
do I need to create a new, unlocked reference?

I'm wrapping a C++ scene graph with Lua, using a
Luna-ish approach. In order to have two way
communication, each Lua table has a pointer to the
underlying C++ instance, and each C++ instance has a
reference to the Lua object. I generally let Lua
control the life-cycle of the objects, so these are
often unlocked lua-refs. 

When the object is added to the scene graph, I call a
GetRef() type method which increments an internal
reference count. If the object has not been
lua-locked, I call lua_ref(L, 1) to get a locked
lua-ref to the object. Now, if the script asks the
object to remove itself from the scene graph, I want
to call lua_unref to unlock the object. However, the
Lua object may still persist, and may even add itself
back to the scene graph at a later point. This seems
to work okay in my brief testing, but can I be
guaranteed that it will work?

Thanks,
Jason
379



__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/