[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Recipe: setfenv with Lua 5.2.0 work3
- From: François Perrad <francois.perrad@...>
- Date: Thu, 20 May 2010 16:48:13 +0200
With Lua 5.1, I have the following code :
setfenv(level, M)
With Lua 5.2.0 work2, I rewrite it as following (compatible with Lua 5.1) :
debug.setfenv(debug.getinfo(level, 'f').func, M)
Now, with Lua 5.2.0 work3, it becomes :
if debug.setupvalue(debug.getinfo(level, 'f').func, 1, M) ~= '_ENV' then
setfenv(level, M) -- Lua 5.1
end
The value 1 seems magical, but I think _ENV is alway the first upvalue.
François.