lua-users home
lua-l archive

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


Hi,

Diego Nehab wrote:
> I am assuming module writers *will* call module(). I was asking if there
> is a way to avoid the global namespace polution without changing every
> package in your systeme not to use module, and without rewriting the
> module function either.

There's no way to intercept the writes to _G, because the underlying
functions use lua_rawset(). You could write a wrapper for require()
that deletes the globals after they have been set. :-)

If you're willing to patch the source, you could modify ll_module()
and luaL_module() to anchor the created namespaces at LUA_REGISTRYINDEX
instead of LUA_GLOBALSINDEX. Or maybe a sub-table of the registry.
Not pretty either.

Bye,
     Mike