move script-manager into core

develop
myk002 2022-12-07 13:26:35 -08:00 committed by Myk Taylor
parent 0d4d10de08
commit e88b1fdfe5
No known key found for this signature in database
7 changed files with 11 additions and 55 deletions

@ -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
================

@ -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.

@ -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;

@ -1,4 +1,4 @@
local _ENV = mkmodule('plugins.script-manager')
local _ENV = mkmodule('script-manager')
local utils = require('utils')

@ -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)

@ -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'

@ -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<PluginCommand> &) {
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;
}