lua-users home
lua-l archive

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


> 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).


> 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. Lua 5.1 offers a more proper way to do this
mapping.

But I think Luacom already builds userdata to represent COM objects,
doesn't it? Can't you attach the __gc on them?

-- Roberto