[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: modules, require, magic
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 17 Oct 2011 19:11:38 -0200
> My opinion is that modules are important enough so that there should
> be a "blessed" way of writing modules, and preferrably a somewhat
> obvious one. There has to be a policy.
The recommended way of writing modules is the trivial way: a module should
return a table with its data and functions. It'd be nice if it also did
not pollute the global environment. In Lua, this is done trivially with:
local M={}
M.version="1.0.2"
function M.f() ... end
...
return M
This way works fine for both 5.1 and 5.2
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).
All my C modules follow this (but do create a global as well). Changing
them to 5.2 is really easy, even removing the creation of the global.
I do not see any big deal here.
- References:
- modules, require, magic, Eduardo Ochs
- Re: modules, require, magic, Javier Guerra Giraldez
- Re: modules, require, magic, Petite Abeille
- Re: modules, require, magic, Sam Roberts
- Re: modules, require, magic, Hisham