MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / jsonContainerToTable

Method jsonContainerToTable

source/core/StarLua.cpp:1371–1397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1369}
1370
1371LuaTable LuaDetail::jsonContainerToTable(LuaEngine& engine, Json const& container) {
1372 if (!container.isType(Json::Type::Array) && !container.isType(Json::Type::Object))
1373 throw LuaException("jsonContainerToTable called on improper json type");
1374
1375 auto table = engine.createTable();
1376 auto nils = insertJsonMetatable(engine, table, container.type());
1377
1378 if (container.isType(Json::Type::Array)) {
1379 auto vlist = container.arrayPtr();
1380 for (size_t i = 0; i < vlist->size(); ++i) {
1381 auto const& val = (*vlist)[i];
1382 if (val)
1383 table.rawSet(i + 1, val);
1384 else
1385 nils.rawSet(i + 1, 0);
1386 }
1387 } else {
1388 for (auto const& pair : *container.objectPtr()) {
1389 if (pair.second)
1390 table.rawSet(pair.first, pair.second);
1391 else
1392 nils.rawSet(pair.first, 0);
1393 }
1394 }
1395
1396 return table;
1397}
1398
1399Maybe<Json> LuaDetail::tableToJsonContainer(LuaTable const& table) {
1400 JsonObject stringEntries;

Callers

nothing calls this directly

Calls 7

arrayPtrMethod · 0.80
rawSetMethod · 0.80
objectPtrMethod · 0.80
createTableMethod · 0.60
isTypeMethod · 0.45
typeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected