lua-users home
lua-l archive

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


Wim Couwenberg wrote:
> In Lua 5 you can use the registry table
> (at virtual index LUA_REGISTRYINDEX) to store any private references
> that you need.

After rethinking this for a bit I think it is in fact easier to store these
references in their userdata's metatable.  Then your __gc meta method need
not even bother with releasing them (if you need a __gc method at all, which
I guess you do if you manage (Windows) resources.)

You could use the registry of course, but that needs some care: the link
between the userdata and the references it contains should be through a
weak-keyed table, or the userdata is not going to be collected.

Also, a recent discussion by Alex, Roberto and Rici on this list seems to be
related and worth studying (subject: GC order.)  (A, R & R: did I still miss
something here?)

Bye,
Wim