tools/script_manager - allow for inclusion of directory/package specific

libraries by adding "local" libraries to the search
                       path to ensure they are found when needed.
This commit is contained in:
Bill Ferguson
2024-04-02 17:54:10 -04:00
parent 40949b3855
commit e78e718769

View File

@@ -509,6 +509,25 @@ local function process_script_data(script_file)
restore_log_level(old_log_level)
end
local function ensure_lib_in_search_path(line)
local old_log_level = set_log_level(sm.log_level)
set_log_level(log.debug)
log.msg(log.debug, "line is " .. line)
if string.match(line, ds.sanitize_lua(dt.configuration.config_dir .. PS .. "lua/lib")) then
log.msg(log.debug, line .. " is already in search path, returning...")
return
end
local path = string.match(line, "(.+)/lib/.+lua")
log.msg(log.debug, "extracted path is " .. path)
log.msg(log.debug, "package.path is " .. package.path)
if not string.match(package.path, ds.sanitize_lua(path)) then
log.msg(log.debug, "path isn't in package.path, adding...")
package.path = package.path .. ";" .. path .. "/?.lua"
log.msg(log.debug, "new package.path is " .. package.path)
end
restore_log_level(old_log_level)
end
local function scan_scripts(script_dir)
local old_log_level = set_log_level(sm.log_level)
local script_count = 0
@@ -529,6 +548,8 @@ local function scan_scripts(script_dir)
process_script_data(script_file)
script_count = script_count + 1
end
else
ensure_lib_in_search_path(line) -- but let's make sure libraries can be found
end
end
end