[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Globals (more ruminations)
- From: David Manura <dm.lua@...>
- Date: Thu, 15 Jul 2010 23:33:33 -0400
On Thu, Jul 15, 2010 at 10:21 PM, David Manura <dm.lua@math2.org> wrote:
> local one = 1
> local two = 2
> local print = print
>
> f(function(_ENV)
> local counter = 1
> global two
> global function one() two() end
> global function two() one() end
> global function three()
> countar = countr + 1
> print(counterr)
> end
> end)
>
> [...] Finally, the global `print` needs to be accessed within the
> environment `_ENV`, which remains a problem because `print` doesn't
> belong inside `_ENV`. That problem may be handled via the various
> usual techniques (`__index=_G` hackery, making `print` a local in the
> outer scope, or making `_G` a local in the outer scope and doing
> `_G.print` inside).
Actually, another option is to replace `local print = print` with
`global print`. At least it's now the case that variables declared
with `global` resolve lexically across nested environments. So,
you'll end up enumerating all top-level standard library variables
like this near the top of your program. Given that it was decided to
avoid failing on gets to undeclared globals in order to avoid that
enumeration, if we'll be doing that anyway then there's no reason not
fail on gets to undeclared globals.
- References:
- Re: Globals (more ruminations), Jim Jennings
- Re: Globals (more ruminations), Mark Hamburg
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Geoff Leyland
- Re: Globals (more ruminations), Alexander Gladysh
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Juri Munkki
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Patrick Donnelly
- Re: Globals (more ruminations), Roberto Ierusalimschy
- Re: Globals (more ruminations), Edgar Toernig
- Re: Globals (more ruminations), David Manura