lua-users home
lua-l archive

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


Hi

Suppose that I want to keep a reference to a Lua object in C, but I don't want to prevent it from being collected. When the Lua object is collected, a full userdata will be collected with it, so I can keep track of when it gets collected, and can take appropriate action to unref the reference. I just don't want to prevent the garbage collection from happening. The 2nd edition of PiL doesn't mention how luaL_ref will work if the object is held in a weak table. Logic tells me that it will work the way I want it to work: The object gets collected if noone else hold a reference to it, the entry gets removed from the table, and if I try to fetch the object with the old reference, I get nil. Can I count on this?

Per