I have a script which I load with loadfile and then run it. Also I have the variable love in the scope of parent lua script and I want this variable be nil inside the child script enivornment but everything else untouched (print, math, pairs, all the std lib of Lua). How can I do that?
This does not work:
local scenario = love.filesystem.load(script)
local env = {}
setmetatable(env, { __index = _G })
env.love = nil
env.game = Game
setfenv(scenario, env)
Your code does not work because
envinherits from_Gand soenv.loveis resolved in_G. Settingenv.love = nildoes not add aloveentry toenv.Set
env.love = falseorenv.love = {}.