LuaAPI: Show quotes around strings in table dumps (#60)

This commit is contained in:
Lion Kortlepel 2021-11-19 12:54:16 +01:00
parent b6fa3574fd
commit f1148ed1c4
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
2 changed files with 14 additions and 14 deletions

View File

@ -96,10 +96,6 @@ void Application::CheckForUpdates() {
} }
} }
// thread name stuff // thread name stuff
static std::map<std::thread::id, std::string> threadNameMap {}; static std::map<std::thread::id, std::string> threadNameMap {};

View File

@ -6,7 +6,7 @@
#define SOL_ALL_SAFETIES_ON 1 #define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp> #include <sol/sol.hpp>
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) { if (Indent > 80) {
return "[[possible recursion, refusing to keep printing]]"; 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(); return ss.str();
} }
case sol::type::string: case sol::type::string:
if (QuoteStrings) {
return "\"" + Value.as<std::string>() + "\"";
} else {
return Value.as<std::string>(); return Value.as<std::string>();
}
case sol::type::number: { case sol::type::number: {
std::stringstream ss; std::stringstream ss;
ss << Value.as<float>(); ss << Value.as<float>();
@ -53,7 +57,7 @@ static std::string LuaToString(const sol::object Value, size_t Indent = 1) {
for (size_t i = 0; i < Indent; ++i) { for (size_t i = 0; i < Indent; ++i) {
Result << "\t"; 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"; Result << "\n";
} }
@ -160,49 +164,49 @@ void LuaAPI::MP::RemoveVehicle(int PID, int VID) {
void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) { void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
switch (ConfigID) { switch (ConfigID) {
case 0: //debug case 0: // debug
if (NewValue.is<bool>()) { if (NewValue.is<bool>()) {
Application::Settings.DebugModeEnabled = NewValue.as<bool>(); Application::Settings.DebugModeEnabled = NewValue.as<bool>();
beammp_info(std::string("Set `Debug` to ") + (Application::Settings.DebugModeEnabled ? "true" : "false")); beammp_info(std::string("Set `Debug` to ") + (Application::Settings.DebugModeEnabled ? "true" : "false"));
} else } else
beammp_lua_error("set invalid argument [2] expected boolean"); beammp_lua_error("set invalid argument [2] expected boolean");
break; break;
case 1: //private case 1: // private
if (NewValue.is<bool>()) { if (NewValue.is<bool>()) {
Application::Settings.Private = NewValue.as<bool>(); Application::Settings.Private = NewValue.as<bool>();
beammp_info(std::string("Set `Private` to ") + (Application::Settings.Private ? "true" : "false")); beammp_info(std::string("Set `Private` to ") + (Application::Settings.Private ? "true" : "false"));
} else } else
beammp_lua_error("set invalid argument [2] expected boolean"); beammp_lua_error("set invalid argument [2] expected boolean");
break; break;
case 2: //max cars case 2: // max cars
if (NewValue.is<int>()) { if (NewValue.is<int>()) {
Application::Settings.MaxCars = NewValue.as<int>(); Application::Settings.MaxCars = NewValue.as<int>();
beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::Settings.MaxCars)); beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::Settings.MaxCars));
} else } else
beammp_lua_error("set invalid argument [2] expected integer"); beammp_lua_error("set invalid argument [2] expected integer");
break; break;
case 3: //max players case 3: // max players
if (NewValue.is<int>()) { if (NewValue.is<int>()) {
Application::Settings.MaxPlayers = NewValue.as<int>(); Application::Settings.MaxPlayers = NewValue.as<int>();
beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::Settings.MaxPlayers)); beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::Settings.MaxPlayers));
} else } else
beammp_lua_error("set invalid argument [2] expected integer"); beammp_lua_error("set invalid argument [2] expected integer");
break; break;
case 4: //Map case 4: // Map
if (NewValue.is<std::string>()) { if (NewValue.is<std::string>()) {
Application::Settings.MapName = NewValue.as<std::string>(); Application::Settings.MapName = NewValue.as<std::string>();
beammp_info(std::string("Set `Map` to ") + Application::Settings.MapName); beammp_info(std::string("Set `Map` to ") + Application::Settings.MapName);
} else } else
beammp_lua_error("set invalid argument [2] expected string"); beammp_lua_error("set invalid argument [2] expected string");
break; break;
case 5: //Name case 5: // Name
if (NewValue.is<std::string>()) { if (NewValue.is<std::string>()) {
Application::Settings.ServerName = NewValue.as<std::string>(); Application::Settings.ServerName = NewValue.as<std::string>();
beammp_info(std::string("Set `Name` to ") + Application::Settings.ServerName); beammp_info(std::string("Set `Name` to ") + Application::Settings.ServerName);
} else } else
beammp_lua_error("set invalid argument [2] expected string"); beammp_lua_error("set invalid argument [2] expected string");
break; break;
case 6: //Desc case 6: // Desc
if (NewValue.is<std::string>()) { if (NewValue.is<std::string>()) {
Application::Settings.ServerDesc = NewValue.as<std::string>(); Application::Settings.ServerDesc = NewValue.as<std::string>();
beammp_info(std::string("Set `Description` to ") + Application::Settings.ServerDesc); beammp_info(std::string("Set `Description` to ") + Application::Settings.ServerDesc);