lua-users home
lua-l archive

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

Roberto Ierusalimschy <> 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

  function load2(ld, src, mode)
    local function ld2()
      coroutine.yield("local _ENV = _G; return function(...) ")
      for s in ld do
      coroutine.yield(" end, function(env) _ENV=env end")
    local f, e = load(coroutine.wrap(ld2), src, mode)
    if f then return f()
    else return nil, e

f.anthony.n.finch  <>
Malin, Hebrides: South or southeast 5 to 7, perhaps gale 8 later. Rough or
very rough. Showers. Moderate or good.