[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How can I avoid changing the _ENV of a whole file when changing the _ENV of a lua function?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sun, 19 Feb 2012 15:59:46 -0200
> If you need to do the above in a loop, make a Lua function which
> returns dummy closures (with unique _ENV upvalues) and cache that
> function:
>
> luaL_loadstring(L, "local _ENV; return function() end");
Detail: if the function does not use _ENV, it will not have the
required unique upvalue:
luaL_loadstring(L, "local _ENV; return function() return x end");
-- Roberto