From 9cc6851cc157c5931b9e449673869ee61c8105f2 Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Wed, 23 Apr 2025 02:52:34 -0400 Subject: [PATCH 1/5] Fix for mods not being properly reloaded on Windows --- docs/about/Authors.rst | 1 + docs/changelog.txt | 1 + library/lua/script-manager.lua | 3 +++ 3 files changed, 5 insertions(+) diff --git a/docs/about/Authors.rst b/docs/about/Authors.rst index d806d92aaa..e8030e881a 100644 --- a/docs/about/Authors.rst +++ b/docs/about/Authors.rst @@ -63,6 +63,7 @@ DoctorVanGogh DoctorVanGogh Donald Ruegsegger hashaash doomchild doomchild Droseran Droseran +dvantwisk dvantwisk DwarvenM DwarvenM Eamon Bode eamondo2 Baron Von Munchhausen EarthPulseAcademy EarthPulseAcademy diff --git a/docs/changelog.txt b/docs/changelog.txt index 94223c2326..30e64c2b99 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -72,6 +72,7 @@ Template for new versions: ## Fixes - `preserve-rooms`: will no longer crash when a civzone is assigned to a unit that does not exist - `gui/design`: fix misaligned shape icons +- `scripts/script-manager`: fix lua scripts in mods not being reloaded properly on Windows. # 51.11-r1 diff --git a/library/lua/script-manager.lua b/library/lua/script-manager.lua index c2647fbe2d..6e9da549c5 100644 --- a/library/lua/script-manager.lua +++ b/library/lua/script-manager.lua @@ -52,6 +52,9 @@ function reload(refresh_active_mod_scripts) local force_refresh_fn = refresh_active_mod_scripts and function(script_path, script_name) if script_path:find('scripts_modactive') then local full_path = script_path..'/'..script_name + if dfhack.getOSType() == 'windows' then + full_path = script_path..'\\'..script_name + end internal_script = dfhack.internal.scripts[full_path] if internal_script then dfhack.internal.scripts[full_path] = nil From 3d0f2969e3cee738646e3a2038558fee679367c1 Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Wed, 23 Apr 2025 13:28:48 -0400 Subject: [PATCH 2/5] Changelog entry modifications --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index dac194aa2f..6f0cd82c8b 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -73,7 +73,7 @@ Template for new versions: ## Fixes - `preserve-rooms`: will no longer crash when a civzone is assigned to a unit that does not exist - `gui/design`: fix misaligned shape icons -- `scripts/script-manager`: fix lua scripts in mods not being reloaded properly on Windows. +- `script-manager`: fix lua scripts in mods not being reloaded properly on Windows. # 51.11-r1 From 6816b676927ab300e7fdf99aa02157b0b235442e Mon Sep 17 00:00:00 2001 From: Dan Van Twisk Date: Wed, 23 Apr 2025 13:33:55 -0400 Subject: [PATCH 3/5] Modified changelog log --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 6f0cd82c8b..12a8fcbe61 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -73,7 +73,7 @@ Template for new versions: ## Fixes - `preserve-rooms`: will no longer crash when a civzone is assigned to a unit that does not exist - `gui/design`: fix misaligned shape icons -- `script-manager`: fix lua scripts in mods not being reloaded properly on Windows. +- `script-manager`: fix lua scripts in mods not being reloaded properly upon entering a saved world on Windows. # 51.11-r1 From 74004612d88d8419af237226bb1329df6ac12589 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 27 Apr 2025 11:02:45 -0700 Subject: [PATCH 4/5] revert windows-specific change to script-manager --- library/lua/script-manager.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/lua/script-manager.lua b/library/lua/script-manager.lua index 71bbd3449e..9a1ecb1df0 100644 --- a/library/lua/script-manager.lua +++ b/library/lua/script-manager.lua @@ -52,9 +52,6 @@ function reload(refresh_active_mod_scripts) local force_refresh_fn = refresh_active_mod_scripts and function(script_path, script_name) if script_path:find('scripts_modactive') then local full_path = script_path..'/'..script_name - if dfhack.getOSType() == 'windows' then - full_path = script_path..'\\'..script_name - end internal_script = dfhack.internal.scripts[full_path] if internal_script then dfhack.internal.scripts[full_path] = nil From b260041a03f93a931dfefe070ec0f12a57e72f1b Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 27 Apr 2025 11:02:54 -0700 Subject: [PATCH 5/5] canonicalize slashes in path returned from findScript --- docs/dev/Lua API.rst | 10 ++++++---- library/LuaApi.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 2c7f9cacbc..bf7ee35eff 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -3338,12 +3338,14 @@ and are only documented here for completeness: * ``dfhack.internal.findScript(name)`` - Searches `script paths ` for the script ``name`` and returns the - path of the first file found, or ``nil`` on failure. + Searches `script paths ` for the script ``name`` (which + includes the ``.lua`` extension) and returns the absolute path of the first + file found, or ``nil`` on failure. Slashes in the path are canonicalized to + forward slashes. .. note:: - This requires an extension to be specified (``.lua`` or ``.rb``) - use - ``dfhack.findScript()`` to include the ``.lua`` extension automatically. + You can use the ``dfhack.findScript()`` wrapper if you want to specify the + script name without the ``.lua`` extension. * ``dfhack.internal.runCommand(command[, use_console])`` diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index c80fecffc2..04b7741828 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -3965,7 +3965,7 @@ static int internal_findScript(lua_State *L) const char *name = luaL_checkstring(L, 1); std::filesystem::path path = Core::getInstance().findScript(name); if (!path.empty()) - lua_pushstring(L, path.string().c_str()); + lua_pushstring(L, Filesystem::as_string(path).c_str()); else lua_pushnil(L); return 1;