[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Implicit Globals - A (better?) compile time solution.
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Mon, 25 Feb 2008 11:22:41 -0500
John Hind wrote:
> I do not see why you say "_G.x" is ugly - unless it is the leading
> underscore which could easily be fixed.
_G is not a language feature but a predefined entry in the default Lua
environment. Custom environments may not have it.
Roberto Ierusalimschy wrote:
> 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.
I personnally like the current implicit global behaviour and would
prefer it to keep the way it is (but since I dislike most announced
changes for 5.2 I'm probably not a typical user).
However if that were to change I think a new declaration mechanism is
needed. Using "name = name" is ok for simple globals, but as soon as you
put a metatable on your environment this can have undesirable side