lua-users home
lua-l archive

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

On Thu, Dec 11, 1997 at 08:03:30PM -0200, Alan Watson wrote:
> > To clarify, my basic problem is that default global 
> > access easily turns typo-bugs into really difficult
> > ones (that can be extremely execution order dependant).
> Since typos also occur in local variable and field names, isn't this
> problem always going to exist in some form?

No. What the original poster was talking about is the problem of not
_noticing_ when you have a local variable typo.

For example:

function test()
     local test_one, test_two, test_three;

     test_one = 1;
     test_two = 2;
     test_tree = 3;

Notice the misspelling of "test_three" as "test_tree". THIS is what
we are trying to prevent. In lua, not only do you not notice at compile,
you don't even notice at RUNTIME! Not unless you happen to make a global
called "test_tree", or you happen to print the global variables or

So we're trying to specify some approach for making this kind of error not
possible. My preference (for my own stuff) is to change the parser so that
you have to explicitly declare what globals you are going to access in a
function if some "strong global checking" is enabled. The above would
signal a syntax error which could be corrected either by adding the

    global test_tree;

To the top of the function (if this is what the code was supposed to do)
or by fixing the spelling of the line to be:

     test_three = 3;

David Jeske (N9LCA) + +