Print entering and leaving lua as raw

This commit is contained in:
Lion Kortlepel 2021-11-29 00:17:09 +01:00
parent 297b646d33
commit c91f3ee33c
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
2 changed files with 8 additions and 5 deletions

View File

@ -94,7 +94,7 @@ void TConsole::BackupOldLog() {
void TConsole::ChangeToLuaConsole() { void TConsole::ChangeToLuaConsole() {
if (!mIsLuaConsole) { if (!mIsLuaConsole) {
mIsLuaConsole = true; mIsLuaConsole = true;
beammp_info("Entered Lua console. To exit, type `exit()`"); Application::Console().WriteRaw("Entered Lua console. To exit, type `exit()`");
mCachedRegularHistory = mCommandline.history(); mCachedRegularHistory = mCommandline.history();
mCommandline.set_history(mCachedLuaHistory); mCommandline.set_history(mCachedLuaHistory);
mCommandline.set_prompt("lua> "); mCommandline.set_prompt("lua> ");
@ -104,7 +104,7 @@ void TConsole::ChangeToLuaConsole() {
void TConsole::ChangeToRegularConsole() { void TConsole::ChangeToRegularConsole() {
if (mIsLuaConsole) { if (mIsLuaConsole) {
mIsLuaConsole = false; mIsLuaConsole = false;
beammp_info("Left Lua console."); Application::Console().WriteRaw("Left Lua console.");
mCachedLuaHistory = mCommandline.history(); mCachedLuaHistory = mCommandline.history();
mCommandline.set_history(mCachedRegularHistory); mCommandline.set_history(mCachedRegularHistory);
mCommandline.set_prompt("> "); mCommandline.set_prompt("> ");
@ -149,8 +149,11 @@ TConsole::TConsole() {
} else if (!cmd.empty()) { } else if (!cmd.empty()) {
auto FutureIsNonNil = auto FutureIsNonNil =
[](const std::shared_ptr<TLuaResult>& Future) { [](const std::shared_ptr<TLuaResult>& Future) {
auto Type = Future->Result.get_type(); if (!Future->Error) {
return Type != sol::type::lua_nil && Type != sol::type::none; auto Type = Future->Result.get_type();
return Type != sol::type::lua_nil && Type != sol::type::none;
}
return false;
}; };
std::vector<std::shared_ptr<TLuaResult>> NonNilFutures; std::vector<std::shared_ptr<TLuaResult>> NonNilFutures;
{ // Futures scope { // Futures scope

View File

@ -408,6 +408,7 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi
lua_atpanic(mState, LuaAPI::PanicHandler); lua_atpanic(mState, LuaAPI::PanicHandler);
// StateView.globals()["package"].get() // StateView.globals()["package"].get()
StateView.set_function("print", &LuaAPI::Print); StateView.set_function("print", &LuaAPI::Print);
StateView.set_function("printRaw", &LuaAPI::MP::PrintRaw);
StateView.set_function("exit", &Application::GracefullyShutdown); StateView.set_function("exit", &Application::GracefullyShutdown);
auto MPTable = StateView.create_named_table("MP"); auto MPTable = StateView.create_named_table("MP");
@ -462,7 +463,6 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi
return Lua_GetPlayerIdentifiers(ID); return Lua_GetPlayerIdentifiers(ID);
}); });
MPTable.set_function("Sleep", &LuaAPI::MP::Sleep); 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) { MPTable.set_function("CreateEventTimer", [&](const std::string& EventName, size_t IntervalMS) {
if (IntervalMS < 25) { 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."); beammp_warn("Timer for \"" + EventName + "\" on \"" + mStateId + "\" is set to trigger at <25ms, which is likely too fast and won't cancel properly.");