[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: a new proposal for environments
- From: Jonathan Castello <twisolar@...>
- Date: Thu, 25 Feb 2010 11:49:50 -0800
> I don't understand what you mean... :-/
> Could you point me to the relevant context?
Lua 5.1:
local new_env = {}
local foo = loadfile("foo.lua")
setfenv(foo, new_env)
Lua 5.2's 'loadin' only works on chunks, not filenames containing
chunks, as far as I know. So I'd have to use the io library to get the
contents, then loadin to load that chunk with the right environment.
dofile() should probably refer to _ENV rather than the original global
environment as well, because it loads and runs a file immediately. I
don't know, it just seems like if code loads other files (or other
code period), the code would expect those files to be in the same
environment unless otherwise specified.
>
> Couldn't you do
> sandbox.load = function(chunk) return loadin(sandbox,chunk) end
> ?
Not really, because the sandboxed code might want to include unrelated
modules that use loadstring or loadfile, which is entirely possible.
You might want those modules in an entirely new environment
(setfenv(foo, {}), but your 'sandbox.load' would load them into the
sandbox environment instead.
- References:
- a new proposal for environments, Roberto Ierusalimschy
- Re: a new proposal for environments, Peter Cawley
- Re: a new proposal for environments, Roberto Ierusalimschy
- Re: a new proposal for environments, David Kastrup
- Re: a new proposal for environments, Enrico Colombini
- Re: a new proposal for environments, Duncan Cross
- Re: a new proposal for environments, Jonathan Castello
- Re: a new proposal for environments, Pierre-Yves Gérardy
- Re: a new proposal for environments, Jonathan Castello
- Re: a new proposal for environments, Pierre-Yves Gérardy