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

Method insertJsonMetatable

source/core/StarLua.cpp:1347–1369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1345}
1346
1347LuaTable LuaDetail::insertJsonMetatable(LuaEngine& engine, LuaTable const& table, Json::Type type) {
1348 auto newIndexMetaMethod = [](LuaTable const& table, LuaValue const& key, LuaValue const& value) {
1349 auto mt = table.getMetatable();
1350 auto nils = mt->rawGet<LuaTable>("__nils");
1351
1352 // If we are setting an entry to nil, need to add a bogus integer entry
1353 // to the __nils table, otherwise need to set the entry *in* the __nils
1354 // table to nil and remove it.
1355 if (value == LuaNil)
1356 nils.rawSet(key, 0);
1357 else
1358 nils.rawSet(key, LuaNil);
1359 table.rawSet(key, value);
1360 };
1361
1362 auto mt = engine.createTable();
1363 auto nils = engine.createTable();
1364 mt.rawSet("__nils", nils);
1365 mt.rawSet("__newindex", engine.createFunction(newIndexMetaMethod));
1366 mt.rawSet("__typehint", type == Json::Type::Array ? 1 : 2);
1367 table.setMetatable(mt);
1368 return nils;
1369}
1370
1371LuaTable LuaDetail::jsonContainerToTable(LuaEngine& engine, Json const& container) {
1372 if (!container.isType(Json::Type::Array) && !container.isType(Json::Type::Object))

Callers

nothing calls this directly

Calls 5

getMetatableMethod · 0.80
rawSetMethod · 0.80
createFunctionMethod · 0.80
setMetatableMethod · 0.80
createTableMethod · 0.60

Tested by

no test coverage detected