lua-users home
lua-l archive

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


Hi,

slonik.az@gmail.com wrote:
> The added bonus is the fact that Lua table can have its own metatable
> that can define __gc metamethod to clean up the resources when this
> shared pool of information is not need anymore. This could happen when
> all the closures that share this table go out of scope.

The __gc metamethod is only called for userdata objects, not for
tables. Look into the archives for lots of threads on this topic
and the reasons why it is this way. Just put a single userdata
into the table or associate all resources with userdata objects.

Another possibility is to share a single userdata amongst
different closures (in an upvalue, not in the function
environment). Userdata objects have an environment table, too.
You can use it to hold arbitrary Lua objects (if you need to).

Bye,
     Mike