lua-users home
lua-l archive

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

Yeah, I could see it happening that way, but I don't know if that's how it actually works.

That would be convenient for me. Create a table entry (light to full) when full is first created; any subsequent access by light userdata gets the same existing full userdata (via that table), and when all references go away, the full userdata is "collectible". If the table is weak, it will be cleaned up when the full userdata is collected. But in the meantime, any new access by light userdata would try to return the same full userdata (which is "collectible"). Is this a problem?

Basically, I'm trying to ensure there can only ever be one full userdata per particular C++ object. (Because that would simplify a lot.)

On Tue, Nov 12, 2013 at 10:28 AM, Javier Guerra Giraldez <> wrote:
On Tue, Nov 12, 2013 at 10:24 AM, Marc Lepage <> wrote:
> 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

as I see it (might be wrong), at step 2, the object isn't "scheduled
for collection", it's "eligible for collection".  it could be
collected at any time while there's no reference to it. but after step
3, there's a new reference, so it's no longer eligible, and it doesn't
get collected.