From c703f3b21b286a4df32ae1bb329a03531e1a2879 Mon Sep 17 00:00:00 2001 From: dhthwy <302825+dhthwy@users.noreply.github.com> Date: Mon, 10 Nov 2025 22:30:56 -0500 Subject: [PATCH 1/2] move prints to console out of help_db get_commands() --- library/Core.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index b927d49cc4..eeb3ea5d94 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -416,13 +416,12 @@ bool is_builtin(color_ostream &con, const std::string &command) { return lua_toboolean(L, -1); } -void get_commands(color_ostream &con, std::vector &commands) { +std::optional get_commands(color_ostream &con, std::vector &commands) { ConditionalCoreSuspender suspend{}; if (!suspend) { - con.printerr("Cannot acquire core lock in helpdb.get_commands\n"); commands.clear(); - return; + return "Cannot acquire core lock in helpdb.get_commands"; } auto L = DFHack::Core::getInstance().getLuaState(); @@ -430,22 +429,26 @@ void get_commands(color_ostream &con, std::vector &commands) { if (!lua_checkstack(L, 1) || !Lua::PushModulePublic(con, L, "helpdb", "get_commands")) { - con.printerr("Failed to load helpdb Lua code\n"); - return; + return "Failed to load helpdb Lua code"; } if (!Lua::SafeCall(con, L, 0, 1)) { - con.printerr("Failed Lua call to helpdb.get_commands.\n"); + return "Failed Lua call to helpdb.get_commands."; } Lua::GetVector(L, commands, top + 1); + return std::nullopt; } static bool try_autocomplete(color_ostream &con, const std::string &first, std::string &completed) { std::vector commands, possible; - get_commands(con, commands); + if (auto err = get_commands(con, commands)) { + con.printerr("%s\n", err->c_str()); + return false; + } + for (auto &command : commands) if (command.substr(0, first.size()) == first) possible.push_back(command); From 1b460ed5cc4651821f9f579bab2acd18352028ce Mon Sep 17 00:00:00 2001 From: dhthwy <302825+dhthwy@users.noreply.github.com> Date: Mon, 10 Nov 2025 23:28:57 -0500 Subject: [PATCH 2/2] fix compile. --- library/Core.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/library/Core.cpp b/library/Core.cpp index eeb3ea5d94..b4fd3195b6 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -84,6 +84,7 @@ distribution. #include #include #include +#include #include #ifdef _WIN32