lua-users home
lua-l archive

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


> Peter Cawley wrote:
> >http://www.corsix.org/content/look-lua-52-work3
> 
> No more "in env do ... end". So what's now the preferred idiom for
> executing a given function in different environments?

"in env do ... end" does not execute a given function in a different
environment. It only changes the environment of what is literally
written inside it.


> (passing the desired environment as an argument and setting_ENV at
> the beginning of the called function?)

If the function collaborates (that is, it has been written to have
a variable environment), my preferred idiom is to pass the environment
as an argument and to get it in a parameter called _ENV in the function.

  function foo (_ENV, a, b, c)
    -- code will run in the environment given as first argument
    ...
  end

-- Roberto