lua-users home
lua-l archive

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


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.