diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index b25b41166..1a2fdc18c 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -5593,9 +5593,9 @@ reloaded. For example:: end The attachment to ``dfhack.onStateChange`` should appear in your script code -outside of any function. The `script-manager` will load your script as a module -when DFHack is initialized, giving this code an opportunity to run and attach -hooks before a game is loaded. +outside of any function. DFHack will load your script as a module just before +the ``SC_DFHACK_INITIALIZED`` state change event is sent, giving your code an +opportunity to run and attach hooks before the game is loaded. Save init script ================ diff --git a/docs/plugins/script-manager.rst b/docs/plugins/script-manager.rst deleted file mode 100644 index 6a2e07f53..000000000 --- a/docs/plugins/script-manager.rst +++ /dev/null @@ -1,14 +0,0 @@ -script-manager -============== - -.. dfhack-tool:: - :summary: Triggers startup tasks for scripts. - :tags: dev - :no-command: - -This plugin loads all scripts that are declared as modules so that they can -put state change hooks in place for loading persistent data. It also scans for -global ``isEnabled()`` functions and gathers them for script enabled state -tracking and reporting for the `enable` command. - -Please see `script-enable-api` for more details. diff --git a/library/Core.cpp b/library/Core.cpp index 33d9c43b2..eed2de30a 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -832,8 +832,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v auto L = Lua::Core::State; Lua::StackUnwinder top(L); - Lua::CallLuaModuleFunction(con, L, - "plugins.script-manager", "list"); + Lua::CallLuaModuleFunction(con, L, "script-manager", "list"); } } else if (first == "ls" || first == "dir") @@ -1838,8 +1837,12 @@ void Core::doUpdate(color_ostream &out, bool first_update) { Lua::Core::Reset(out, "DF code execution"); - if (first_update) + if (first_update) { + auto L = Lua::Core::State; + Lua::StackUnwinder top(L); + Lua::CallLuaModuleFunction(out, L, "script-manager", "reload"); onStateChange(out, SC_CORE_INITIALIZED); + } // find the current viewscreen df::viewscreen *screen = NULL; diff --git a/plugins/lua/script-manager.lua b/library/lua/script-manager.lua similarity index 97% rename from plugins/lua/script-manager.lua rename to library/lua/script-manager.lua index 919db077b..ef0c1fede 100644 --- a/plugins/lua/script-manager.lua +++ b/library/lua/script-manager.lua @@ -1,4 +1,4 @@ -local _ENV = mkmodule('plugins.script-manager') +local _ENV = mkmodule('script-manager') local utils = require('utils') diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 78bf63903..3ad19efb4 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -154,7 +154,6 @@ if(BUILD_SUPPORTED) dfhack_plugin(rename rename.cpp LINK_LIBRARIES lua PROTOBUFS rename) add_subdirectory(rendermax) dfhack_plugin(reveal reveal.cpp LINK_LIBRARIES lua) - dfhack_plugin(script-manager script-manager.cpp LINK_LIBRARIES lua) dfhack_plugin(search search.cpp) dfhack_plugin(seedwatch seedwatch.cpp) dfhack_plugin(showmood showmood.cpp) diff --git a/plugins/lua/overlay.lua b/plugins/lua/overlay.lua index 95148e8b8..9f2c9029b 100644 --- a/plugins/lua/overlay.lua +++ b/plugins/lua/overlay.lua @@ -2,11 +2,10 @@ local _ENV = mkmodule('plugins.overlay') local gui = require('gui') local json = require('json') +local scriptmanager = require('script-manager') local utils = require('utils') local widgets = require('gui.widgets') -local scriptmanager = require('plugins.script-manager') - local OVERLAY_CONFIG_FILE = 'dfhack-config/overlay.json' local OVERLAY_WIDGETS_VAR = 'OVERLAY_WIDGETS' diff --git a/plugins/script-manager.cpp b/plugins/script-manager.cpp deleted file mode 100644 index 767819f93..000000000 --- a/plugins/script-manager.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "Debug.h" -#include "LuaTools.h" -#include "PluginManager.h" - -using std::string; -using std::vector; - -using namespace DFHack; - -DFHACK_PLUGIN("script-manager"); - -namespace DFHack { - DBG_DECLARE(script_manager, log, DebugCategory::LINFO); -} - -DFhackCExport command_result plugin_init(color_ostream &, std::vector &) { - return CR_OK; -} - -DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) { - if (event != SC_CORE_INITIALIZED) - return CR_OK; - - DEBUG(log,out).print("scanning scripts for onStateChange() functions\n"); - - auto L = Lua::Core::State; - Lua::StackUnwinder top(L); - Lua::CallLuaModuleFunction(out, L, "plugins.script-manager", "reload"); - - return CR_OK; -}