MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / cson_to_table

Function cson_to_table

lua/sp.c:5319–5351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5317}
5318
5319static int cson_to_table(Lua lua, cson_value *v)
5320{
5321 if (cson_value_is_object(v)) {
5322 cson_object *o = cson_value_get_object(v);
5323 cson_object_iterator i;
5324 cson_object_iter_init(o, &i);
5325 cson_kvp *kv;
5326 /* Make sure we have enough space to store "key" and "value". */
5327 if (lua_checkstack(lua, 2) == 0)
5328 return -1;
5329 while ((kv = cson_object_iter_next(&i)) != NULL) {
5330 lua_pushstring(lua, cson_string_cstr(cson_kvp_key(kv)));
5331 if (cson_push_value(lua, cson_kvp_value(kv)) != 0) return -1;
5332 lua_settable(lua, -3);
5333 }
5334 } else if (cson_value_is_array(v)) {
5335 cson_array *a = cson_value_get_array(v);
5336 unsigned int i, len = cson_array_length_get(a);
5337 /*
5338 * Make sure we have enough space to store one value to be pushed into
5339 * the array.
5340 */
5341 if (lua_checkstack(lua, 1) == 0)
5342 return -1;
5343 for (i = 0; i < len; ++i) {
5344 if (cson_push_value(lua, cson_array_get(a, i)) != 0) return -1;
5345 lua_rawseti(lua, -2, i + 1);
5346 }
5347 } else {
5348 return -1;
5349 }
5350 return 0;
5351}
5352
5353static int cson_push_null(Lua L, const char *type)
5354{

Callers 2

cson_push_valueFunction · 0.85
cson_to_table_annotatedFunction · 0.85

Calls 15

cson_value_is_objectFunction · 0.85
cson_value_get_objectFunction · 0.85
cson_object_iter_initFunction · 0.85
lua_checkstackFunction · 0.85
cson_object_iter_nextFunction · 0.85
lua_pushstringFunction · 0.85
cson_string_cstrFunction · 0.85
cson_kvp_keyFunction · 0.85
cson_push_valueFunction · 0.85
cson_kvp_valueFunction · 0.85
lua_settableFunction · 0.85
cson_value_is_arrayFunction · 0.85

Tested by

no test coverage detected