lua-users home
lua-l archive

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


Mark Hamburg wrote:
>
> What I'd like to see is an option to require that all variables be
> explicitly declared as either global or local.

You are aware that this would require something like this:

    global io,math,table,...
    global require,print,tostring,type,pcall,error,...

at the beginning of nearly every script?

To make it somehow useable you would need an include-statement.
And that means a build-environment for the compiler.  Ad-hoc
scripts with i.e. dostring become complicated.

One could say, forget the include statement, I'm willing to
declare every single global.  One goes even further and says,
the checks are only activated by the first global statement
(to stay backward compatible and to give the programmer a
choice).  But then I guess, you'll notice that you constantly
mistype field-names (and that includes functions in a library's
module table - i.e. io.opem) and all the hassle starts again:
a structure statement, typed variables, ...

Ciao, ET.

PS: I'm not against a global statement as outlined above.  It
could give a little bit more checking with moderate additional
work.  I just think that it will not be enough to satisfy the
people who use it regularly.  It only scratches the surface.