lua-users home
lua-l archive

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


> No more "in env do ... end". So what's now the preferred idiom for 
> executing a given function in different environments?
> 
> (passing the desired environment as an argument and setting_ENV at the 
> beginning of the called function?)

You could write your function to be run in different environments:

function f(_ENV,...)
	... -- code that never even mentions _ENV!
end

Or you could provide a setter:

do
	local _ENV=_ENV
	function setenv_for_f(env)
		_ENV=env
	end
	function f(...)
		...
	end
end