lua-users home
lua-l archive

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


In addition to putting code in modules, I am now in a position where I'd like to sometimes unload them.

I know about this function:

function unrequire(m)
    package.loaded[m] = nil
    _G[m] = nil
end

I find it works great if I call it from a global area: if I require, unrequire, require, I get a different table.

But I am not finding it working like that if I call it from within a module itself. Even though package.loaded[m] and _G[m] are nil (I can check these by storing _G in a local), require gets me back the same module.

So I am wondering, are there any tricks to using unrequire from within a module itself (to ensure another module is unloaded)?

BTW this is all in Lua (no C).