lua-users home
lua-l archive

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


Rici Lake wrote:


On 19-Aug-05, at 7:04 AM, Antero Vipunen wrote:

Ok. Then why not to do the following: create a userdata with proper __gc metametod(it's only destiny will be to assure the proper finalization), and assign it to some field of module, or set as upvalue for one of the module functions(for example Z_init()). When the module gets collected then so does it's fields...


You probably meant "all of the module functions". It is conceivable that one of the module functions could be collected while the other ones are still in use. For example, what happens if the module table gets collected, but some program has retained a reference to some module function.


Oh my god. Then we should create an internal counter and (yes) set an upvalue for all module functions, because module is not_used iff all of it functions are not referenced.

Pseudo code to clarify my idea:

int __gc(lua_State *L) {
 static int counter = 0;
if(++counter == NUMBER_OF_FUNCTIONS_IN_MODULE)
   Z_fini();
}

AMDG,
 Antero Vipunen.