From 8f6f1e4430467e8faec298d9df9c0b51a0e5f154 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 15 Oct 2023 10:50:57 +0300 Subject: [PATCH] don't limit amount of console messages in queue --- src/game_api/script/lua_vm.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/game_api/script/lua_vm.cpp b/src/game_api/script/lua_vm.cpp index f7a2fb1f9..b7e681085 100644 --- a/src/game_api/script/lua_vm.cpp +++ b/src/game_api/script/lua_vm.cpp @@ -363,20 +363,28 @@ end /// Standard lua print function, prints directly to the terminal but not to the game lua["lua_print"] = lua["print"]; + /// Print a log message on screen. lua["print"] = [](std::string message) -> void { auto backend = LuaBackend::get_calling_backend(); + bool is_console = !strcmp(backend->get_id(), "dev/lua_console"); backend->messages.push_back({message, std::chrono::system_clock::now(), ImVec4(1.0f, 1.0f, 1.0f, 1.0f)}); - if (backend->messages.size() > 20) + if (backend->messages.size() > 40 && !is_console) backend->messages.pop_front(); backend->lua["lua_print"](message); }; - /// Print a log message to ingame console. - lua["console_print"] = [](std::string message) -> void + /// Print a log message to ingame console with a comment identifying the script that sent it. + lua["console_print"] = [&lua](std::string message) -> void { auto backend = LuaBackend::get_calling_backend(); + bool is_console = !strcmp(backend->get_id(), "dev/lua_console"); + if (is_console) + { + lua["print"](std::move(message)); + return; + } auto in_time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::tm time_buf; localtime_s(&time_buf, &in_time_t);