[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: luaL_ref on tables with weak values?
- From: Per Bull Holmen <pbholmen@...>
- Date: Fri, 12 Feb 2010 02:11:16 -0800 (PST)
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?