lua-users home
lua-l archive

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


On 22.10.2011 01:07, Sam Roberts wrote:
On Fri, Oct 21, 2011 at 3:59 PM, Philipp Janda<siffiejoe@gmx.net>  wrote:
On 21.10.2011 20:49, Sam Roberts wrote:

[...]

I'd say the single biggest problem with losing module is that we have
to port everything to 5.2, and do it in a way that also works for 5.1
(which will be here a long time).

Just use the proposed module-less module system -- it will work for Lua 5.1
and 5.2 (no matter what is decided for the future of "module")!

You say "just use", but you mean is "rewrite everything".

You seem to be making the point that it is possible to write modules
in 5.2, but I don't dispute that, not does anyone else.

I just said that there is a way to write modules that will work with Lua 5.1 and Lua 5.2. It seems that the official module function will change one way or the other, so you probably will need to adapt your modules.


I just don't want to rewrite everything for dubious advantage.

The proposed common idiom for 5.2 is:
local M = {}
function M.f() end

Like prepending M. to the start of every function defined in my modules.

You could also write:
local protocol = { tcp = require"protocol.tcp" }

The point is: The user of the module has the choice!

A module has one definition, and many users, your proposal means
modifying every use of the module to construct the namespace implicit
in the module name. Of course, instead, I'd rewrite require to do
this.

If your modules are written for your own closed environment you could just reimplement the Lua 5.1 module function for Lua 5.2 and be done with it. This will probably be the least amount of rewriting.


Sam


Philipp