use setHotkeyCmd instead of dfhack.run_script

develop
myk002 2021-05-14 23:02:04 -07:00
parent b0dba22e72
commit 5a149f44e0
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 13 additions and 33 deletions

@ -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<string> &parameters)
{
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 &param : 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<string> &parameters)
{
if (parameters.size() >= 1 && parameters[0] == "gui")
{
return do_gui(parameters) ? CR_OK : CR_FAILURE;
std::ostringstream command;
command << "gui/blueprint";
for (const string &param : 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;

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