lua-users home
lua-l archive

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


On Tue, Oct 18, 2011 at 8:39 AM, Pierre Chapuis <catwell@archlinux.us> wrote:
> On Mon, 17 Oct 2011 19:11:38 -0200, Luiz Henrique de Figueiredo wrote:
>
>> local M={}
>> M.version="1.0.2"
>> function M.f() ... end
>> ...
>> return M
>
>> There is no need for a module function and no need for syntax either.
>> No one needs to know about _ENV for that only for complicated things
>> like avoiding writing "M." (probably not a good idea as it serves as
>> documentation of what is exported).
>
> I use an alternative construction that does the same thing in the end:
>
> local f = function() ... end
> return {
>  version = "1.0.2",
>  f = f,
> }
>
> I also think modules shouldn't modify the global namespace.
> This solution doesn't allow concatenation of module files but this is
> a small price to pay for a simple, understandable module mechanism.
>
> --
> Pierre Chapuis
>
>

module...
Localise external functions so they remain accessible after the call
to module or use seeall to make _G the __index of the new
environment's metatable, call module creating a global table, making
it the environment of the current block so following global sets and
gets happen to the module table not the global environment.

not module...
return a table with exports.

I just don't understand _why_ you want the functional equivalent of
module 'foo' when all you ever need is trivial and much more obvious
without it.