[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: globals (_locals)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 06 Jun 2001 15:59:03 -0300
> So how do things work at the global scope? Unless there is some good reason
> to make the global keyword required there, it would be nice not to.
I am not sure whether this is a good reason, but currently in Lua the
"global scope" has exactly the same semantics of any other function. You
can always enclose any chunk between "function ()" - "end" and everything
works fine.
If we assume that a global declaration works as a switch to turn on
declaration mode, and that global declarations respect scopes,
then the following could work:
a = 3; -- OK, default is declaration mode (dmode) off
function f() -- OK
global b -- turns on dmode (only inside f)
b = 1
c = 1 -- ERROR; c is undeclared
end
x = 4; -- OK; out of scope of "global b", so back to dmode off
On the other hand, if the chunk starts with "global", then everything
in it will inherit the dmode on.
-- Roberto