Skip to content

Commit 19fdbc1

Browse files
authored
Merge pull request #461 from wpferguson/reimplement_ensure_lib_in_path
reimplemented ensure_lib_in_path with a windows aware path specification
2 parents 9d6ff85 + 63d5aad commit 19fdbc1

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tools/script_manager.lua

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,35 @@ local function process_script_data(script_file)
509509
restore_log_level(old_log_level)
510510
end
511511

512+
local function ensure_lib_in_search_path(line)
513+
local old_log_level = set_log_level(sm.log_level)
514+
set_log_level(log.debug)
515+
516+
log.msg(log.debug, "line is " .. line)
517+
518+
if string.match(line, ds.sanitize_lua(dt.configuration.config_dir .. PS .. "lua" .. PS .. "lib")) then
519+
log.msg(log.debug, line .. " is already in search path, returning...")
520+
return
521+
end
522+
523+
local pattern = dt.configuration.running_os == "windows" and "(.+)\\lib\\.+lua" or "(.+)/lib/.+lua"
524+
local path = string.match(line, pattern)
525+
526+
log.msg(log.debug, "extracted path is " .. path)
527+
log.msg(log.debug, "package.path is " .. package.path)
528+
529+
if not string.match(package.path, ds.sanitize_lua(path)) then
530+
531+
log.msg(log.debug, "path isn't in package.path, adding...")
532+
533+
package.path = package.path .. ";" .. path .. "/?.lua"
534+
535+
log.msg(log.debug, "new package.path is " .. package.path)
536+
end
537+
538+
restore_log_level(old_log_level)
539+
end
540+
512541
local function scan_scripts(script_dir)
513542
local old_log_level = set_log_level(sm.log_level)
514543
local script_count = 0
@@ -530,7 +559,7 @@ local function scan_scripts(script_dir)
530559
script_count = script_count + 1
531560
end
532561
else
533-
-- ensure_lib_in_search_path(line) -- but let's make sure libraries can be found
562+
ensure_lib_in_search_path(line) -- but let's make sure libraries can be found
534563
end
535564
end
536565
end

0 commit comments

Comments
 (0)