agentzh wrote: > package.loaded["ffi"] = nil This isn't the proper way to unload a module, nor is it documented as such. Certainly not for core modules. [Actually, there's no safe way to unload arbitrary modules, even for plain Lua. C modules may depend on each other and unloading them in the wrong order will wreak havoc. And if there's still a userdata with a __gc C function around and you remove the shared library from the address space with the above method ... guess what happens.] > We really need this usage because it is handy to reload an external > FFI-based Lua module without destroying and recreating the "world" > (i.e., the whole Lua VM) during either Lua code development or hot > code replacement in production. Or do you have better suggestions? Sorry, but I guess unloading the FFI module would never work well. There may still be cdata objects around, there may be JIT-compiled code that depends on the FFI module, there are tons of internal dependencies, etc. I guess recreating the whole VM is the safest bet. [That might still get you into trouble even without the FFI: it unloads/reloads the binding libraries, but might not unload the underlying C libraries (e.g. lua-zip + libzip). And even if you manage to do that, some C libs do not take it well if they are unloaded (though libzip is probably ok -- just an example).] --Mike