lua-users home
lua-l archive

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

Roberto Ierusalimschy wrote:
In short, what you do is create a weak-valued table which maps
from dummy created-on-demant heavyuserdata to your {}s - the __gc
sits on the userdata and thus indirectly gets called when the {}
becomes collectable.

A simpler way is to store the dummy created-on-demant heavyuserdata
directly in your {}, using a reserved key (e.g., __userdata).

That's possible but pollutes the original table (but that
might not be a problem for objects, where you wouldn't
usually for example want to do a pairs() over the table).

You then need a way to map back from the userdata to the table

Since this userdata is dummy anyway, you can store the table as the
userdata's metatable.

That's a very nice idea (though then, surely, the __gc field has
to go into the table itself and the same pollution occurs as above).

> Lua 5.1 offers a more proper way to do this mapping.

Neat.  Any examples?

Adam D. Moss   -