lua-users home
lua-l archive

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


I'm new to Lua, but most of my current site is written in CRM-114, which is a shared memory language - unscoped. As soon as I had learned to use that language and had about 1200 lines in production, someone introduced a fork with lexical scope. This was a source of a great deal of anxiety and the fork did break a couple of scripts, but I tested it and ended up using it. This situation isn't terribly different from that one except that Lua has a few million more users. :)

My understanding of this change here is that it operates on the mechanics of the way scope is implemented in the VM, but not the way it behaves in user space... except to apply some fairly intuitive limits to global variables initialized in modules. The result should be improved module safety with a limited amount of code overhead for packagers. Lua will still be global by default, but global now means global to an environment rather than global to an instance of the interpreter. Addressing variables in that environment will be transparent for module users, but packagers will need to be explicit about what goes 'off-world'.

As for the 'example'... Scope will still nest. The environment for the nested chunk is the same as the environment where the local was defined. No change. Sigils and any other thread of conversation spawned from a fear of scope changing is reasoning from a faulty premise.

Signoff
Chris

Ignoring antichrist references from my Android phone.

On Aug 10, 2010 10:01 AM, "Javier Guerra Giraldez" <javier@guerrag.com> wrote:

On Tue, Aug 10, 2010 at 11:57 AM, Everett L Williams II
<rett@classicnet.net> wrote:
> All declarati...

you're forgetting that 'local by default' simply doesn't work with
lexical scoping.  the final result would be something like what David
mentioned

--
Javier