lua-users home
lua-l archive

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

> a = { ....whatever ... }
> b = { __gc = function ...finalizer stuff... end }
> setmetatable(a,b)
> Then when "a" is collected it will run the __gc function in the metatable.
> That doesn't seem to work currently.   Or how to I get this type of
> functionality?  I have a table that has some external state information that
> needs to be cleaned up when the table is destroyed.  Is my only choice to
> manually call some sort of cleanup function before killing the table?

Set that "external state information" as a userdata value inside "a" and
set a __gc method for that userdata.

Or try newproxy (undocumented). See this for instance: