[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: require, module, globals and "magic"
- From: Petite Abeille <petite.abeille@...>
- Date: Mon, 16 Aug 2010 15:42:13 +0200
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 :))
- References:
- require, module, globals and "magic", Nevin Flanagan
- Re: require, module, globals and "magic", steve donovan
- Re: require, module, globals and "magic", Lorenzo Donati
- Re: require, module, globals and "magic", steve donovan
- Re: require, module, globals and "magic", steve donovan
- Re: require, module, globals and "magic", Luiz Henrique de Figueiredo
- Re: require, module, globals and "magic", Petite Abeille
- Re: require, module, globals and "magic", Jerome Vuarand