| 50 | |
| 51 | template <ScriptContext context> |
| 52 | void DecodeJsonTable(HSQUIRRELVM sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj) |
| 53 | { |
| 54 | g_pSquirrel[context]->newtable(sqvm); |
| 55 | |
| 56 | for (auto itr = obj->MemberBegin(); itr != obj->MemberEnd(); itr++) |
| 57 | { |
| 58 | switch (itr->value.GetType()) |
| 59 | { |
| 60 | case rapidjson::kObjectType: |
| 61 | g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1); |
| 62 | DecodeJsonTable<context>( |
| 63 | sqvm, (rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>*)&itr->value); |
| 64 | g_pSquirrel[context]->newslot(sqvm, -3, false); |
| 65 | break; |
| 66 | case rapidjson::kArrayType: |
| 67 | g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1); |
| 68 | DecodeJsonArray<context>( |
| 69 | sqvm, (rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>*)&itr->value); |
| 70 | g_pSquirrel[context]->newslot(sqvm, -3, false); |
| 71 | break; |
| 72 | case rapidjson::kStringType: |
| 73 | g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1); |
| 74 | g_pSquirrel[context]->pushstring(sqvm, itr->value.GetString(), -1); |
| 75 | |
| 76 | g_pSquirrel[context]->newslot(sqvm, -3, false); |
| 77 | break; |
| 78 | case rapidjson::kTrueType: |
| 79 | case rapidjson::kFalseType: |
| 80 | g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1); |
| 81 | g_pSquirrel[context]->pushbool(sqvm, itr->value.GetBool()); |
| 82 | g_pSquirrel[context]->newslot(sqvm, -3, false); |
| 83 | break; |
| 84 | case rapidjson::kNumberType: |
| 85 | if (itr->value.IsDouble() || itr->value.IsFloat()) |
| 86 | { |
| 87 | g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1); |
| 88 | g_pSquirrel[context]->pushfloat(sqvm, itr->value.GetFloat()); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1); |
| 93 | g_pSquirrel[context]->pushinteger(sqvm, itr->value.GetInt()); |
| 94 | } |
| 95 | g_pSquirrel[context]->newslot(sqvm, -3, false); |
| 96 | break; |
| 97 | case rapidjson::kNullType: |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | template <ScriptContext context> void EncodeJSONTable( |
| 104 | SQTable* table, |
nothing calls this directly
no test coverage detected