lua-users home
lua-l archive

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

 > Norman Ramsey wrote:
 > > The only way I can think of to do this is to use a weak table in
 > > which both keys and values are weak and the light userdata is the
 > > key, the heavy userdata is the value.  Is this the correct approach?
 > > Are there other possible approaches?  
 > I think that won't work. Light userdata are simple values like numbers
 > and booleans, they are stored directly in tables, not by reference. Thus
 > the light userdata as a weak key will make the value associated (the
 > full userdata) immediately collectable.

Ouch!  Roberto, have I mentioned recently how useful it would be to
have a formal semantics for parts of Lua?

 > AFAIK the only way to handle your situation is to pass around the full
 > big userdata (which is handle by reference, so it's just a pointer
 > passed around), or eventually a smaller (but still full) userdata which
 > contains only the array pointer. In that case you have to link the big
 > and small (full) userdatas in some way (with a weak table or the
 > metatable/environment mechanisms).

Urgh.  Well, sometimes that's the way the cookie crumbles.