lua-users home
lua-l archive

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


On Aug 16, 2010, at 2:38 PM, Jerome Vuarand wrote:

>> (1) register module with _LOADED (lauxlib.luaL_pushmodule)
>> (2) initialize module's _M, _NAME and _PACKAGE (loadlib.modinit)
>> (3) execute options (lauxlib.dooptions)
> 
> OK.

Ok. That must nearly qualify as unconditional consensus :)

> 
>> (4) set the _ENV of the caller to be the module (lauxlib.set_env).
> 
> Not OK, the move to _ENV is to give back to closure the control of
> their global variables. If the module wants to change its _ENV, it
> should do so explicitly :
> 
> _ENV = module(... or 'test', package.seeall)

I would argue that this is precisely a feature belonging in module(): declare a module and set its environment, all at once. In my point of view, this is a feature, not a bug, irrespectively of details implementation (setfenv vs. _ENV).

In short, aside from the global name space pollution, module() has a well defined, agreed upon behavior which nicely balance require(), bringing peace and harmony to Lua :))