From 5a149f44e0c1787213968c414b5748e4c1c415e5 Mon Sep 17 00:00:00 2001 From: myk002 Date: Fri, 14 May 2021 23:02:04 -0700 Subject: [PATCH] use setHotkeyCmd instead of dfhack.run_script --- plugins/blueprint.cpp | 38 +++++++++++++------------------------- plugins/lua/blueprint.lua | 8 -------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/plugins/blueprint.cpp b/plugins/blueprint.cpp index 38a03bff7..723e3f1a2 100644 --- a/plugins/blueprint.cpp +++ b/plugins/blueprint.cpp @@ -691,7 +691,7 @@ static bool get_options(blueprint_options &opts, !Lua::PushModulePublic( out, L, "plugins.blueprint", "parse_commandline")) { - out.printerr("Failed to load blueprint Lua code"); + out.printerr("Failed to load blueprint Lua code\n"); return false; } @@ -706,28 +706,6 @@ static bool get_options(blueprint_options &opts, return true; } -static bool do_gui(const vector ¶meters) -{ - auto L = Lua::Core::State; - color_ostream_proxy out(Core::getInstance().getConsole()); - Lua::StackUnwinder top(L); - - if (!lua_checkstack(L, parameters.size() + 1) || - !Lua::PushModulePublic(out, L, "plugins.blueprint", "do_gui")) - { - out.printerr("Failed to load blueprint Lua code"); - return false; - } - - for (const string ¶m : parameters) - Lua::Push(L, param); - - if (!Lua::SafeCall(out, L, parameters.size(), 0)) - return false; - - return true; -} - static void print_help() { auto L = Lua::Core::State; @@ -738,7 +716,7 @@ static void print_help() !Lua::PushModulePublic(out, L, "plugins.blueprint", "print_help") || !Lua::SafeCall(out, L, 0, 0)) { - out.printerr("Failed to load blueprint Lua code"); + out.printerr("Failed to load blueprint Lua code\n"); } } @@ -746,7 +724,17 @@ command_result blueprint(color_ostream &out, vector ¶meters) { if (parameters.size() >= 1 && parameters[0] == "gui") { - return do_gui(parameters) ? CR_OK : CR_FAILURE; + std::ostringstream command; + command << "gui/blueprint"; + for (const string ¶m : parameters) + { + command << " " << param; + } + string command_str = command.str(); + out.print("launching %s\n", command_str.c_str()); + + Core::getInstance().setHotkeyCmd(command_str); + return CR_OK; } blueprint_options options; diff --git a/plugins/lua/blueprint.lua b/plugins/lua/blueprint.lua index 5dacf40bc..7580f17e3 100644 --- a/plugins/lua/blueprint.lua +++ b/plugins/lua/blueprint.lua @@ -134,14 +134,6 @@ function parse_commandline(opts, ...) parse_positionals(opts, positionals, depth and 4 or 3) end -function do_gui(command, ...) - local args = {...} - print(('launching gui/blueprint %s'):format(table.concat(args, ' '))) - dfhack.timeout(1, 'frames', - function() dfhack.run_script('gui/blueprint', - table.unpack(args)) end) -end - -- compatibility with old exported API. we route the request back through -- run_command so we have a unified path for parameter processing and invariant -- checking.