lua-users home
lua-l archive

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


> 1.  When you call lua_ref(true) to lock an object that C knows about but 
> lua doesn't have any way to reference, does lua_unref unlock the object?  
Yes. It will be collected the next time the garbage collector is activated.

> What if lua_ref(true) is called multiple times on the same lua object?  
> is the object only freed when that many lua_unrefs are called?
Yes. lua_unref gets the reference as its argument, so you must unref each
reference that you created for that object.

> 2.  Can you lua_ref(true) an object with no name:
>         lua_pushstring("this is a nameless object on the stack");
>         ref = lua_ref(true);
Yes, no problem at all.

> Where does such an object live?  Can you get to it from within lua?
It lives in a "reference" table. You cannot access it from within Lua
(sometimes this is very useful for security...)

> Note: lock has to be true in this case since lua definitely does not have 
> a reference to the string object (right?).
Yes. Otherwise the object will be garbage collected (and lua_getref will
return LUA_NOOBJECT next time you call it).


-- Roberto