lua-users home
lua-l archive

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


> Is it possible for a C library dynamically loaded into Lua to be 
> unloaded, complete with a call to FreeLibrary or dlclose, without 
> closing the Lua state?  If so, what requirements must such a C library 
> meet to be safely unloadable?  Thanks.

I think it must ensure that there are no references left to the C functions
it exports. The only way I know to do this is to add a fixed upvalue to each
exported function. In Lua 5.1 you can also arrange for the exported functions
to share the same (private) environment. In both cases, you then have to
set up a __gc metamethod for the upvalue or environment table. When this
metamethod is called, you do whatever clean up is needed by your library and
then you can unload it (though I'm not sure a library can be unloaded from
within itself). --lhf