Skip to content

Commit

Permalink
Merge branch 'develop' into adv-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jan 10, 2025
2 parents 9efec6e + e9be4ce commit 232af61
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
33 changes: 31 additions & 2 deletions library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,17 @@ bool is_builtin(color_ostream &con, const std::string &command) {
}

void get_commands(color_ostream &con, std::vector<std::string> &commands) {
#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Cannot acquire core lock in helpdb.get_commands\n");
commands.clear();
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);
Expand Down Expand Up @@ -626,12 +630,17 @@ static std::string sc_event_name (state_change_event id) {
}

void help_helper(color_ostream &con, const std::string &entry_name) {
#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Failed Lua call to helpdb.help (could not acquire core lock).\n");
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);

Expand All @@ -649,7 +658,17 @@ void help_helper(color_ostream &con, const std::string &entry_name) {
}

void tags_helper(color_ostream &con, const std::string &tag) {
#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Failed Lua call to helpdb.help (could not acquire core lock).\n");
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);

Expand Down Expand Up @@ -686,7 +705,17 @@ void ls_helper(color_ostream &con, const std::vector<std::string> &params) {
filter.push_back(str);
}

#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Failed Lua call to helpdb.help (could not acquire core lock).\n");
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);

Expand All @@ -706,7 +735,7 @@ void ls_helper(color_ostream &con, const std::vector<std::string> &params) {
}
}

command_result Core::runCommand(color_ostream &con, const std::string &first_, std::vector<std::string> &parts)
command_result Core::runCommand(color_ostream &con, const std::string &first_, std::vector<std::string> &parts, bool no_autocomplete)
{
std::string first = first_;
CommandDepthCounter counter;
Expand Down Expand Up @@ -1273,7 +1302,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, s
}
if ( lua )
res = runLuaScript(con, first, parts);
else if ( try_autocomplete(con, first, completed) )
else if (!no_autocomplete && try_autocomplete(con, first, completed))
res = CR_NOT_IMPLEMENTED;
else
con.printerr("%s is not a recognized command.\n", first.c_str());
Expand Down
2 changes: 1 addition & 1 deletion library/LuaTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ static void interrupt_hook (lua_State *L, lua_Debug *ar)

bool DFHack::Lua::Interrupt (bool force)
{
lua_State *L = DFHack::Core::getInstance().getLuaState();
lua_State *L = DFHack::Core::getInstance().getLuaState(true);
if (L->hook != interrupt_hook && !force)
return false;
if (force)
Expand Down
4 changes: 3 additions & 1 deletion library/RemoteTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,9 @@ command_result CoreService::RunCommand(color_ostream &stream,
for (int i = 0; i < in->arguments_size(); i++)
args.push_back(in->arguments(i));

return Core::getInstance().runCommand(stream, cmd, args);
// disable try_autocomplete in runCommand so misspellings of kill-lua won't cause deadlocks
// this remote server connection could be the last chance for recovering from stuck Lua scripts
return Core::getInstance().runCommand(stream, cmd, args, true);
}

command_result CoreService::CoreSuspend(color_ostream &stream, const EmptyMessage*, IntMessage *cnt)
Expand Down
2 changes: 1 addition & 1 deletion library/include/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace DFHack
/// returns a named pointer.
void *GetData(std::string key);

command_result runCommand(color_ostream &out, const std::string &command, std::vector <std::string> &parameters);
command_result runCommand(color_ostream &out, const std::string &command, std::vector <std::string> &parameters, bool no_autocomplete = false);
command_result runCommand(color_ostream &out, const std::string &command);
bool loadScriptFile(color_ostream &out, std::string fname, bool silent = false);

Expand Down
2 changes: 1 addition & 1 deletion plugins/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static bool invoke_command(color_ostream &out, const size_t index) {
static command_result hotkeys_cmd(color_ostream &out, vector <string> & parameters) {
if (!parameters.size()) {
DEBUG(log).print("invoking command: '%s'\n", INVOKE_MENU_DEFAULT_COMMAND.c_str());
return Core::getInstance().runCommand(out, INVOKE_MENU_DEFAULT_COMMAND );
return Core::getInstance().runCommand(out, INVOKE_MENU_DEFAULT_COMMAND);
} else if (parameters.size() == 2 && parameters[0] == "menu") {
string cmd = INVOKE_MENU_BASE_COMMAND + parameters[1];
DEBUG(log).print("invoking command: '%s'\n", cmd.c_str());
Expand Down

0 comments on commit 232af61

Please sign in to comment.