lua-users home
lua-l archive

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


2010/2/12 Per Bull Holmen <pbholmen@yahoo.com>:
> Per Bull Holmen wrote:
>> 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.
>
> Sorry, guys, I should have searched the archive better:
>
> http://lua-users.org/lists/lua-l/2002-01/msg00437.html
>
> I believe this means I CAN use luaL_ref on a weak table, and things will work as expected. Sorry for asking something I should have found through searching...!!

You're right, the behavior of the reference created by luaL_ref
depends on the table in which you create that reference. The registry,
which is often used with luaL_ref, keeps hard references.