| 1345 | } |
| 1346 | |
| 1347 | LuaTable 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 | |
| 1371 | LuaTable LuaDetail::jsonContainerToTable(LuaEngine& engine, Json const& container) { |
| 1372 | if (!container.isType(Json::Type::Array) && !container.isType(Json::Type::Object)) |
nothing calls this directly
no test coverage detected