lua-users home
lua-l archive

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


> Am I correct that weak-keyed tables can end up pointing to finalized
> userdata in the keys?

Yes.


> If this is the case, why are things done this way?

It is not uncommon to use a weaktable to associate attributes to
userdata (userdata is the key, attribute is the value). In such uses, it
is also not uncommon that the finalizer code needs those attributes. So
Lua does not remove those keys before calling the finalizer. We assume
that this should not cause problems, because the only way to access
that pair would be using the userdata as a key, but as the program does
not have access to that userdata anymore, it could not access that
entry. (Of course, that is not true if you traverse the table.  But
traversing a weak table is a tricky task anyway...)

-- Roberto