lua-users home
lua-l archive

setfenv(0,tbl) in Lua 5.1

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


I'm trying to understand the exact behavior of thread environments in
Lua 5.1. (I am familiar with the changes introduced in 5.2.)
>From the Lua 5.1 ref manual, I would expect the following to print
false, however it prints true:
flag = true
local newG = { flag = false}
local coroutine, print,setfenv = coroutine,print,setfenv
coroutine.wrap(function()
 setfenv(0, newG)
 print(flag)
end)()
Can someone explain? And what could be written in place of `print(flag)`
that would rely on newG for the lookup? getfenv(0) does return newG,
but any functions or new coroutine calls I insert there still seem to be
using the original _G.
-- 
Jim Pryor
dubiousjim@gmail.com

AltStyle によって変換されたページ (->オリジナル) /