lua-users home
lua-l archive

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

On 19.10.2011 02:21, Petite Abeille wrote:

On Oct 19, 2011, at 2:14 AM, Matthew Wild wrote:

The only things you're keen on is the changing of
the environment for you, and the setting of package.loaded?

And the reopening of module. And the default keys (_NAME, etc).

In short, the module functionalities as they exists today short of _G.

- package.loaded is set by require anyways
- reopening is easy: instead of
local _M = {}
you write
local _M = require( "somemodule" )
- _NAME is in '...'
- _M is still _M if you want

So whats missing is the custom environment and _PACKAGE.
In Lua 5.2 you can set a custom environment, with __index set to _G, in a modified version of require, and as long as you keep module table and environment table separate, your modules will still work with regular require and you don't pollute your module table with unwanted globals. Actually, I would like this behavior for regular require, but I doubt that the Lua authors are willing to completely ban setting globals in Lua modules. You could even add _PACKAGE et al. to your custom environment but then your modules become incompatible with regular require. For Lua 5.1 there is another way for making sure that modules behave and don't set global variables: by using luac and grepping for setglobal.

Did I miss anything?