From c91f3ee33c3087dd12bfb76a977f7cd7a3dfbc2a Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Mon, 29 Nov 2021 00:17:09 +0100 Subject: [PATCH] Print entering and leaving lua as raw --- src/TConsole.cpp | 11 +++++++---- src/TLuaEngine.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/TConsole.cpp b/src/TConsole.cpp index b45a0a7..da71a78 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -94,7 +94,7 @@ void TConsole::BackupOldLog() { void TConsole::ChangeToLuaConsole() { if (!mIsLuaConsole) { mIsLuaConsole = true; - beammp_info("Entered Lua console. To exit, type `exit()`"); + Application::Console().WriteRaw("Entered Lua console. To exit, type `exit()`"); mCachedRegularHistory = mCommandline.history(); mCommandline.set_history(mCachedLuaHistory); mCommandline.set_prompt("lua> "); @@ -104,7 +104,7 @@ void TConsole::ChangeToLuaConsole() { void TConsole::ChangeToRegularConsole() { if (mIsLuaConsole) { mIsLuaConsole = false; - beammp_info("Left Lua console."); + Application::Console().WriteRaw("Left Lua console."); mCachedLuaHistory = mCommandline.history(); mCommandline.set_history(mCachedRegularHistory); mCommandline.set_prompt("> "); @@ -149,8 +149,11 @@ TConsole::TConsole() { } else if (!cmd.empty()) { auto FutureIsNonNil = [](const std::shared_ptr& Future) { - auto Type = Future->Result.get_type(); - return Type != sol::type::lua_nil && Type != sol::type::none; + if (!Future->Error) { + auto Type = Future->Result.get_type(); + return Type != sol::type::lua_nil && Type != sol::type::none; + } + return false; }; std::vector> NonNilFutures; { // Futures scope diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index b493f75..72e0b94 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -408,6 +408,7 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi lua_atpanic(mState, LuaAPI::PanicHandler); // StateView.globals()["package"].get() StateView.set_function("print", &LuaAPI::Print); + StateView.set_function("printRaw", &LuaAPI::MP::PrintRaw); StateView.set_function("exit", &Application::GracefullyShutdown); auto MPTable = StateView.create_named_table("MP"); @@ -462,7 +463,6 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi return Lua_GetPlayerIdentifiers(ID); }); MPTable.set_function("Sleep", &LuaAPI::MP::Sleep); - MPTable.set_function("PrintRaw", &LuaAPI::MP::PrintRaw); MPTable.set_function("CreateEventTimer", [&](const std::string& EventName, size_t IntervalMS) { if (IntervalMS < 25) { beammp_warn("Timer for \"" + EventName + "\" on \"" + mStateId + "\" is set to trigger at <25ms, which is likely too fast and won't cancel properly.");