lua-users home
lua-l archive

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


On 2012-11-13 12:24 PM, "Rapin Patrick" <rapin.patrick@gmail.com> wrote:
>
> I'm not really advocating for a new "global" or "unset" keyword for this case, as I have never felt the necessity for it up to now.
> But I just thought a new "global" keyword could be used for the much more common use case of enforcing declaration of all variables.
> A bit like "strict.lua" but more reliable, since it could be checked at compile time.
> The ceck should remain an option to switch on, though.
>

That seems like a good idea as well. "global x" would normally just parse as "x" (i.e. the "global" keyword does nothing), but by passing a flag like --strict to the interpreter, it would warn you if you refer to x without "declaring" it with the "global" keyword.
But I note that the only difference between that and strict.lua is that you'd be able to write "global x,y" instead of "global('x', 'y')" (and it might be slightly faster, but for debug modes this doesn't really matter)... hardly seems worth hacking the compiler for (and not letting --strict be an argument to the script itself).

But maybe that's different from what you had in mind?