[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Globals (more ruminations)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 16 Jul 2010 13:38:32 -0300
> I think the best way to disallow global access would be to disable
> the environment by explicitly assigning nil to _ENV:
>
> do
> local oldenv = _ENV
> local _ENV = nil --or not local if that's how it works
>
> a = 12345 --would result in "error: no environment"
> end
Repeating again: the point is not to disallow global access, but to
prevent unintended creation of globals. Changing the environment
prevents the unintended creation of globals, but at a high cost (no
more access to globals including the standard libraries):
do
local _ENV = nil
a = 12345 --would result in "error: no environment"; fine
local a = 12 -- fine, 'a' now is local
print(a) -- oops; error...
end
-- Roberto
- References:
- 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
- Re: Globals (more ruminations), David Manura
- Re: Globals (more ruminations), Stuart P. Bentley