lua-users home
lua-l archive

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


Op Di. 13 Nov. 2018 om 18:57 het Roberto Ierusalimschy
<roberto@inf.puc-rio.br> geskryf:
>
> > That's a no. _ENV is set when a chunk is compiled. If you specify a
> > different value for the environment for a chunk and you do not provide
> > access (direct or indirect) to the global environment you have no access to
> > that global environment. This is a feature, otherwise you could not build a
> > sandbox.
>
> Gé's last sentence is crucial in this discussion.

Apart from 'debug' and '_G', the sandbox must also not contain the
library functions 'load' and 'loadfile'.

local load = load
_ENV = {print=print}
getglobal = function(name)
  return load("return "..name)()
end
print(getglobal"math".pi)  --> 3.1415926535898