lua-users home
lua-l archive

Re: modules, require, magic

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


On 2011年10月17日 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

AltStyle によって変換されたページ (->オリジナル) /