lua-users home
lua-l archive

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



On Thursday 03 February 2011 6:35:32 pm Luiz Henrique de Figueiredo wrote:
> > "unrequire" successfully removes the Lua visible references to a C shared library, but it doesn't actually unload it from the memory. From what I can tell, ll_unloadlib() is only called when the userdata with the shared library handle is GC'ed ( which usually is when the Lua state is closed, since the userdata is in the registry )
> 
> You're right. You need to remove that userdata in the registry and then
> collect garbage, perhaps twice, since the userdata has a finalizer.
> To get the registry, call debug.getregistry(). Then search for a key
> of the form "LOADLIB: "..x where x contains the name of your module.
> 

I had forgotten about the debug library. Thank you for pointing this out. It's actually fairly easy to unload a shared library using the way you suggested. So this solves my problem. Thank you!

I've uploaded an "unrequire()" function to Lua Snippets [http://snippets.luacode.org/snippets/unrequire_121] if anybody is interested.

Peter