From df756f22f88bb9fc50dad25106949cd293f3233f Mon Sep 17 00:00:00 2001 From: Warmist Date: Mon, 2 Sep 2019 18:35:46 +0300 Subject: [PATCH] Change dwarfmonitor to use global lua state. This needs more CoreSuspends but they are needed either way. This way you can access other script environments and access this plugin enviroment from lua. --- plugins/dwarfmonitor.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index 29d0198b3..7fadff32f 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -163,7 +163,6 @@ namespace dm_lua { delete out; out = NULL; } - lua_close(state); } bool init_call (const char *func) { @@ -1873,6 +1872,12 @@ static bool set_monitoring_mode(const string &mode, const bool &state) if (!is_enabled) return false; + /* + NOTE: although we are not touching DF directly but there might be + code running that uses these values. So this could use another mutex + or just suspend the core while we edit our values. + */ + CoreSuspender guard; if (mode == "work" || mode == "all") { @@ -1908,7 +1913,10 @@ static bool load_config() DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) { if (enable) + { + CoreSuspender guard; load_config(); + } if (is_enabled != enable) { if (!INTERPOSE_HOOK(dwarf_monitor_hook, render).apply(enable)) @@ -1963,16 +1971,19 @@ static command_result dwarfmonitor_cmd(color_ostream &out, vector & par } else if (cmd == 's' || cmd == 'S') { + CoreSuspender guard; if(Maps::IsValid()) Screen::show(dts::make_unique(), plugin_self); } else if (cmd == 'p' || cmd == 'P') { + CoreSuspender guard; if(Maps::IsValid()) Screen::show(dts::make_unique(), plugin_self); } else if (cmd == 'r' || cmd == 'R') { + CoreSuspender guard; load_config(); } else @@ -2024,7 +2035,7 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector