lua-users home
lua-l archive

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

Hi, I'm not sure if the manual or wiki talked about this, if so point me to the section and I'll be glad to read up on it again.

If I have some Lua references to a full userdata, and elsewhere I have a weak table of light userdata to full userdata so I can look them up.

At some point, I may lose all my strong references to the full userdata in Lua. So the object becomes "collectible". But I'm guessing that it might not be collected at that very moment? And the weak reference won't go away right away?

So the situation I want to avoid is this:

1) You have Lua references to full userdata (and weak references in the table)
2) The Lua references go away (but the weak reference in the table remains)
3) Later in Lua I try to get access to the light userdata and reuse the full userdata because it remains in the table as a weak reference
4) And that full userdata is still scheduled for collection

Because step 3 occurs in C code: I am asking for a Lua reference to a full userdata representing a C object, and it will check the table first to return an existing one (if it exists).

Or, does doing step 3 prevent the collection from occurring, by resurrecting the object (making new references to it)?