From f1148ed1c46b159c6a061b37f419f3045f5eb735 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 19 Nov 2021 12:54:16 +0100 Subject: [PATCH] LuaAPI: Show quotes around strings in table dumps (#60) --- src/Common.cpp | 4 ---- src/LuaAPI.cpp | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Common.cpp b/src/Common.cpp index 158c5a9..b1641a9 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -96,10 +96,6 @@ void Application::CheckForUpdates() { } } - - - - // thread name stuff static std::map threadNameMap {}; diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp index d420d9a..d1ff0a8 100644 --- a/src/LuaAPI.cpp +++ b/src/LuaAPI.cpp @@ -6,7 +6,7 @@ #define SOL_ALL_SAFETIES_ON 1 #include -static std::string LuaToString(const sol::object Value, size_t Indent = 1) { +static std::string LuaToString(const sol::object Value, size_t Indent = 1, bool QuoteStrings = false) { if (Indent > 80) { return "[[possible recursion, refusing to keep printing]]"; } @@ -32,7 +32,11 @@ static std::string LuaToString(const sol::object Value, size_t Indent = 1) { return ss.str(); } case sol::type::string: - return Value.as(); + if (QuoteStrings) { + return "\"" + Value.as() + "\""; + } else { + return Value.as(); + } case sol::type::number: { std::stringstream ss; ss << Value.as(); @@ -53,7 +57,7 @@ static std::string LuaToString(const sol::object Value, size_t Indent = 1) { for (size_t i = 0; i < Indent; ++i) { Result << "\t"; } - Result << LuaToString(Entry.first, Indent + 1) << ": " << LuaToString(Entry.second, Indent + 1) << ","; + Result << LuaToString(Entry.first, Indent + 1) << ": " << LuaToString(Entry.second, Indent + 1, true) << ","; } Result << "\n"; } @@ -160,49 +164,49 @@ void LuaAPI::MP::RemoveVehicle(int PID, int VID) { void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) { switch (ConfigID) { - case 0: //debug + case 0: // debug if (NewValue.is()) { Application::Settings.DebugModeEnabled = NewValue.as(); beammp_info(std::string("Set `Debug` to ") + (Application::Settings.DebugModeEnabled ? "true" : "false")); } else beammp_lua_error("set invalid argument [2] expected boolean"); break; - case 1: //private + case 1: // private if (NewValue.is()) { Application::Settings.Private = NewValue.as(); beammp_info(std::string("Set `Private` to ") + (Application::Settings.Private ? "true" : "false")); } else beammp_lua_error("set invalid argument [2] expected boolean"); break; - case 2: //max cars + case 2: // max cars if (NewValue.is()) { Application::Settings.MaxCars = NewValue.as(); beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::Settings.MaxCars)); } else beammp_lua_error("set invalid argument [2] expected integer"); break; - case 3: //max players + case 3: // max players if (NewValue.is()) { Application::Settings.MaxPlayers = NewValue.as(); beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::Settings.MaxPlayers)); } else beammp_lua_error("set invalid argument [2] expected integer"); break; - case 4: //Map + case 4: // Map if (NewValue.is()) { Application::Settings.MapName = NewValue.as(); beammp_info(std::string("Set `Map` to ") + Application::Settings.MapName); } else beammp_lua_error("set invalid argument [2] expected string"); break; - case 5: //Name + case 5: // Name if (NewValue.is()) { Application::Settings.ServerName = NewValue.as(); beammp_info(std::string("Set `Name` to ") + Application::Settings.ServerName); } else beammp_lua_error("set invalid argument [2] expected string"); break; - case 6: //Desc + case 6: // Desc if (NewValue.is()) { Application::Settings.ServerDesc = NewValue.as(); beammp_info(std::string("Set `Description` to ") + Application::Settings.ServerDesc);