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";
} }