mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 17:09:05 -05:00
Add support for arrays in luascript topic (#913)
This commit is contained in:
@@ -69,7 +69,7 @@ namespace {
|
||||
return "[" + formatLuaString(it.key()) + "] = " + formatLua(it);
|
||||
}
|
||||
|
||||
std::string formatLuaTable(const nlohmann::json& json) {
|
||||
std::string formatObjectAsLuaTable(const nlohmann::json& json) {
|
||||
std::string output = "{";
|
||||
auto it = json.begin();
|
||||
for (size_t i = 0; i < json.size(); ++i, ++it) {
|
||||
@@ -81,9 +81,24 @@ namespace {
|
||||
return output + "}";
|
||||
}
|
||||
|
||||
std::string formatArrayAsLuaTable(const nlohmann::json& json) {
|
||||
std::string output = "{";
|
||||
auto it = json.begin();
|
||||
for (size_t i = 0; i < json.size(); ++i, ++it) {
|
||||
output += formatLua(it);
|
||||
if (i < json.size() - 1) {
|
||||
output += ",";
|
||||
}
|
||||
}
|
||||
return output + "}";
|
||||
}
|
||||
|
||||
std::string formatLua(const nlohmann::json::const_iterator& it) {
|
||||
if (it->is_object()) {
|
||||
return formatLuaTable(it->get<nlohmann::json>());
|
||||
return formatObjectAsLuaTable(it->get<nlohmann::json>());
|
||||
}
|
||||
if (it->is_array()) {
|
||||
return formatArrayAsLuaTable(it->get<nlohmann::json>());
|
||||
}
|
||||
if (it->is_number()) {
|
||||
return fmt::format("{:E}", it->get<double>());
|
||||
|
||||
Reference in New Issue
Block a user