local FuncEnv={}
setmetatable(FuncEnv, {__index = _G})
local func=loadfile("a.lua")
setfenv(func,FuncEnv)()--等价于setfenv(func,FuncEnv);func();
--func()
--FuncEnv.test()
print(FuncEnv.abc)
setmetatable(_G, {
__newindex = function (_, k)
print("Attempt to write to undeclared variable " .. k)
end,
__index = function (_, k)
print("Attempt to read undeclared variable " .. k)
end
})