lua-users home
lua-l archive

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


Maybe a (partial?) solution to the implicit global problem would be to
follow the style of strict.lua, but at compile time. There would be
only one rule:

- an assignment to an "unseen" global inside a function raises a
compile-time error.

"Unseen" means that that global has not been used before in that chunk.

To use a global inside a function, you may need to "declare" it. If the
global belongs to the chunk, a simple "name = nil" in the global level
will do.  Otherwise you may use something like "name = name". It is
strange, but it is (or should be) uncommon for a function to mess with
globals declared elsewhere.

(Question: in "a = a + 1", should the second 'a' be a valid "declaration"
for the first one?)

-- Roberto