Restore lua environment persistence and update modified timestamp correctly

See #544
develop
lethosor 2015-02-10 16:36:08 -05:00
parent e3b67b2985
commit 337598e0d6
1 changed files with 6 additions and 9 deletions

@ -444,21 +444,18 @@ function dfhack.run_script_with_env(envVars,name,...)
local perr local perr
local time = dfhack.filesystem.mtime(file) local time = dfhack.filesystem.mtime(file)
if time == scriptMtime[file] then if time == scriptMtime[file] then
f = scripts[file].runScript f = scripts[file].__runScript__
else else
env = {}
setmetatable(env, { __index = base_env })
for x,y in pairs(envVars or {}) do
env[x] = y
end
--reload --reload
f,perr = loadfile(file, 't', env) f, perr = loadfile(file, 't', env)
if not f then if not f then
error(perr) error(perr)
end end
-- avoid updating mtime if the script failed to load
scriptMtime[file] = time
end end
scripts[file] = env scripts[file] = env
env.runScript = f env.__runScript__ = f
return f(...), env return f(...), env
end end