lua-users home
lua-l archive

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


On Oct 16, 2011, at 7:24 PM, Roberto Ierusalimschy wrote:

>> In 5.1, one can easily bundle multiple modules per Lua file, or
>> concatenate multiple modules into one file, or package the entire
>> enchilada in one binary file, courtesy of luac, without any fuss.
> 
> In Lua 5.2, I think you can easily write something like the following,
> for multiple modules in one file:
> 
> do   -- Module 1
>  local _ENV = mymodule("mod1")
>  ...
> end
> 
> do   -- Module 2
>  local _ENV = mymodule("mod2")
>  ...
> end
> 
> where 'mymodule' is a somewhat trivial function.

As oppose to:

module( 'mod1' )

...

module( 'mod2' )

...

This is a clear regression. 

Trivial or not, module complements require and provides valuable functionalities (in contrast  to, say, table.pack).

At the risk of repeating myself verbatim [1]:

While part of the the behavior of lauxlib.luaL_pushmodule might be controversial (mangling global variables), the other functionalities of loadlib.ll_module are useful in and by themselves. Namely, (1) register module with _LOADED (lauxlib.luaL_pushmodule), (2) initialize module's _M, _NAME and _PACKAGE (loadlib.modinit), (3) execute options (lauxlib.dooptions), and (4) set the _ENV of the caller to be the module (lauxlib.set_env).

Keep these functionalities. Get rid of luaL_pushmodules' lua_pushglobaltable if you must. 


[1] http://lua-users.org/lists/lua-l/2010-08/msg00310.html