MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / json_parse_object_context

Function json_parse_object_context

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:1138–1186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1136}
1137
1138static void json_parse_object_context(lua_State *l, json_parse_t *json)
1139{
1140 json_token_t token;
1141
1142 /* 3 slots required:
1143 * .., table, key, value */
1144 json_decode_descend(l, json, 3);
1145
1146 lua_newtable(l);
1147
1148 json_next_token(json, &token);
1149
1150 /* Handle empty objects */
1151 if (token.type == T_OBJ_END) {
1152 json_decode_ascend(json);
1153 return;
1154 }
1155
1156 while (1) {
1157 if (token.type != T_STRING)
1158 json_throw_parse_error(l, json, "object key string", &token);
1159
1160 /* Push key */
1161 lua_pushlstring(l, token.value.string, token.string_len);
1162
1163 json_next_token(json, &token);
1164 if (token.type != T_COLON)
1165 json_throw_parse_error(l, json, "colon", &token);
1166
1167 /* Fetch value */
1168 json_next_token(json, &token);
1169 json_process_value(l, json, &token);
1170
1171 /* Set key = value */
1172 lua_rawset(l, -3);
1173
1174 json_next_token(json, &token);
1175
1176 if (token.type == T_OBJ_END) {
1177 json_decode_ascend(json);
1178 return;
1179 }
1180
1181 if (token.type != T_COMMA)
1182 json_throw_parse_error(l, json, "comma or object end", &token);
1183
1184 json_next_token(json, &token);
1185 }
1186}
1187
1188/* Handle the array context */
1189static void json_parse_array_context(lua_State *l, json_parse_t *json)

Callers 1

json_process_valueFunction · 0.85

Calls 5

json_decode_descendFunction · 0.85
json_next_tokenFunction · 0.85
json_decode_ascendFunction · 0.85
json_throw_parse_errorFunction · 0.85
json_process_valueFunction · 0.85

Tested by

no test coverage detected