Merge remote-tracking branch 'myk002/myk_invalidate_scripts' into develop

develop
lethosor 2021-03-31 00:50:31 -04:00
commit 8129fdab4e
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 25 additions and 1 deletions

@ -82,6 +82,27 @@ local function clean_require(module)
return require(module)
end
-- forces clean load of scripts directly or indirectly included from the test
-- file. we use our own scripts table instead of the one in dfhack.internal so
-- we don't affect the state scripts that are used outside the test harness.
local test_scripts = {}
local test_envvars = {}
local function clean_reqscript(name)
local path = dfhack.findScript(name)
if test_scripts[path] then return test_scripts[path].env end
local _, env = dfhack.run_script_with_env(
test_envvars,
name,
{
scripts=test_scripts,
module=true,
module_strict=true
})
return env
end
test_envvars.require = clean_require
test_envvars.reqscript = clean_reqscript
local function ensure_title_screen()
if df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then
return
@ -129,6 +150,7 @@ local function build_test_env()
expect = {},
delay = delay,
require = clean_require,
reqscript = clean_reqscript,
}
local private = {
checks = 0,

@ -562,7 +562,6 @@ function Script:get_flags()
end
internal.scripts = internal.scripts or {}
local scripts = internal.scripts
local hack_path = dfhack.getHackPath()
@ -583,6 +582,7 @@ local valid_script_flags = {
module_strict = {required = false},
alias = {required = false},
alias_count = {required = false},
scripts = {required = false},
}
function dfhack.run_script(name,...)
@ -603,6 +603,7 @@ end
reqscript = dfhack.reqscript
function dfhack.script_environment(name, strict)
local scripts = internal.scripts
local path = dfhack.findScript(name)
if not scripts[path] or scripts[path]:needs_update() then
local _, env = dfhack.run_script_with_env(nil, name, {
@ -625,6 +626,7 @@ function dfhack.run_script_with_env(envVars, name, flags, ...)
error('Could not find script ' .. name)
end
local scripts = flags.scripts or internal.scripts
if scripts[file] == nil then
scripts[file] = Script(file)
end