[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua registry, environment, and threads.
- From: Fabien <fleutot+lua@...>
- Date: Sat, 9 Jan 2010 21:31:17 +0100
On Fri, Jan 8, 2010 at 3:13 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> On Fri, Jan 08, 2010 at 11:31:02AM -0200, Roberto Ierusalimschy wrote:
> Maybe I missed something, but if the choice is between switching on a
> compatibility flag that makes the new 'in ... do ... end' construct pretty
> unusable (see Mike's example) or switching it off and make all old code
> using 'module()' unusable... I'd prefer having no compatiblity flag at all,
> and maybe call it 6.0 instead of 5.2.
It would be trivial to include a new 'module' function (the only real
problem being how to call it) that does not change the environment.
New code uses "in newmodule() do ... end", old code continues to use
"module()".
But I do not undestand why the single module function is "unusable".
Usually chunks define a single module, so there is no code after the
'end' for this quite common usage. In particular, this style is
mandatory with the old module function. (That was the reason we opted
to not define a new module function.)
As stated elsewhere about 'arg' vs. '...', deprecated interfaces enabled by default tend to keep being used, turning the language into a kludge. Unkludginess (at the price of some backward incompatibility) is one of Lua's defining characteristic, please don't give it up.
Moreover, for most people ,'module' is the only environment-altering function they'll ever use; if it doesn't respect 'in ... do ... end' lexical scope, you could as well get rid of the construct.
Alternative solution:
I understand that you want the module-loading function to be called "module", while limiting backward compatibility issues. What if you call the old module function, say, legacy_module(), and add in base lib the equivalent of:
function package.preload.module51() module=legacy_module end
This way, adding a single 'require "module51"' at the beginning of an application makes all indirectly required modules lua 51 compatible. You can even do it from the command line with "lua -lmodule51 ...".
-- Fabien.
- References:
- Re: Lua registry, environment, and threads., Christian Tellefsen
- Re: Lua registry, environment, and threads., Mark Hamburg
- Re: Lua registry, environment, and threads., Patrick Donnelly
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Mike Pall
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Mike Pall
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Enrico Tassi
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy