lua-users home
lua-l archive

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


Actually, another option is to replace `local print = print` with
`global print`.

I like this idea (which is to say, I like the idea of having syntactic sugar to localize variables out of the environment, assuming that's what this was suggesting). I don't see the use of a "global" keyword that means the same thing as "_G." (or "_ENV.").

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

The loss would be the ability to use the environment of upper closures by assigning nil to _ENV (assuming that's how it works now, with _ENV falling through), which I couldn't see being that much of a problem as long as you save the current environment in a local before removing your environment.