lua-users home
lua-l archive

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


On Wed, Feb 24, 2010 at 11:38 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> We also came up with a new concept for environments in Lua 5.2; its
> main merit is simplicity. Lua functions do not have environments any
> more. The construction "in env do ... end" is gone too. The new rules
> are really simple:

This seems like a sensible move. One thing that does strike me,
though, is that it does mean that you can no longer simply set the
global variable _G to nil and not worry about your sandboxed users
messing with the global scope in obscure ways - they will always have
access to _ENV. For example, if you don't want them to be able to
discover every global variable, you need to find a way to stop
pairs(_ENV) or next(_ENV) from working - e.g. change _ENV into an
empty proxy table and give it a metatable with __index, __newindex and
__metatable set. Or if you don't want them to be able to create global
variables with names that are not valid identifiers, you will need to
make __newindex a function that verifies the key, as it is now always
possible to use _ENV[key] to set/get arbitrary keys. I'm not saying
this is a serious argument against the proposal, it is just something
subtle that people might be relying on without realising it.

-Duncan