lua-users home
lua-l archive

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

On Thu, Jul 5, 2018 at 12:11 PM, Dirk Laurie <> wrote:
> 2018-07-05 10:40 GMT+02:00 Viacheslav Usov <>:
>> On Thu, Jul 5, 2018 at 8:47 AM Marc Balmer <> wrote:
>>> How was I unclear or neutral when I wrote "It's a bad idea?".
>> That was not in response to "is this a problem worth solving",
> So the OP's diatribe against globals is to be split in three parts,
> each requiring that its predecessor is taken for granted.
> (a) the status quo is bad;
> (b) we need a way to specify whether a variable is global;
> (c) one such way is to put a dollar sign in front of the name.

I'd add a distinction between folks who think the way globals are
handled should stay the way it is and folks who are fine with it as is
but wouldn't mind if it changed.

I'd expect many Lua users to fall in that category.

Or folks who are split on the question. From a language standpoint, I
think it would be nice to have a distinct syntax for locals and
globals. From an ecosystem point of view, I'd be wary of such a

A possible half-solution (that would trigger runtime errors) based on
the current language would be to do

    local _, _ENV = _ENV, nil

You can replace `nil` with a table whose `__index` and `__newindex`
metamethods throw nicer errors (I have a `noglobals()` helper for that
with Lua 5.1 compat as well).

Then you can access `_.print`, etc, which is syntactically distinct
from locals. Compiler errors would still be better though.