[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: setting _ENV in Lua 5.2 when loading a file...?
- From: Tony Finch <dot@...>
- Date: Thu, 10 Nov 2011 15:15:32 +0000
Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>
> The real question is how frequent people need to change the environment
> of trusted code. (And how frequent people need to change the environment
> in general.)
Would it make sense for the load functions to do something like the
following by default? That is, return two values, the loaded function and
its personalized environment setter. (I don't mean you would implement it
like this - I just used coroutines for brevity, and the _G is a bit
handwavey.)
function load2(ld, src, mode)
local function ld2()
coroutine.yield("local _ENV = _G; return function(...) ")
for s in ld do
coroutine.yield(s)
end
coroutine.yield(" end, function(env) _ENV=env end")
end
local f, e = load(coroutine.wrap(ld2), src, mode)
if f then return f()
else return nil, e
end
end
Tony.
--
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
Malin, Hebrides: South or southeast 5 to 7, perhaps gale 8 later. Rough or
very rough. Showers. Moderate or good.
- References:
- setting _ENV in Lua 5.2 when loading a file...?, Miles Bader
- Re: setting _ENV in Lua 5.2 when loading a file...?, Petite Abeille
- Re: setting _ENV in Lua 5.2 when loading a file...?, Miles Bader
- Re: setting _ENV in Lua 5.2 when loading a file...?, Michal Kottman
- Re: setting _ENV in Lua 5.2 when loading a file...?, Miles Bader
- Re: setting _ENV in Lua 5.2 when loading a file...?, Roberto Ierusalimschy
- Re: setting _ENV in Lua 5.2 when loading a file...?, Matthew Frazier
- Re: setting _ENV in Lua 5.2 when loading a file...?, Roberto Ierusalimschy
- Re: setting _ENV in Lua 5.2 when loading a file...?, Patrick Rapin
- Re: setting _ENV in Lua 5.2 when loading a file...?, Roberto Ierusalimschy