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

Function table_to_cson

lua/sp.c:5560–5723  ·  view source on GitHub ↗

value to convert is on top of stack

Source from the content-addressed store, hash-verified

5558
5559// value to convert is on top of stack
5560static cson_value *table_to_cson(Lua L, int lvl, json_conv *conv)
5561{
5562 const char *type = NULL;
5563 ++lvl;
5564 if (lvl > 100 || lua_checkstack(L, 1) == 0) {
5565 conv->error = "too many nested tables";
5566 conv->reason |= CONV_REASON_ARGS_FATAL;
5567 return NULL;
5568 }
5569 cson_value *v = NULL;
5570 long long integer;
5571 double dbl;
5572
5573 dbtypes_enum dbtype = luabb_dbtype(L, -1);
5574 if (dbtype > DBTYPES_MINTYPE && dbtype < DBTYPES_MAXTYPE) { // null chk
5575 const lua_dbtypes_t *nullchk = lua_touserdata(L, -1);
5576 if (nullchk->is_null) {
5577 switch (dbtype) {
5578 case DBTYPES_CSTRING: type = "cstring"; break;
5579 case DBTYPES_INTEGER: type = "integer"; break;
5580 case DBTYPES_REAL: type = "double"; break;
5581 case DBTYPES_BLOB: type = "blob"; break;
5582 case DBTYPES_DATETIME: type = "datetime"; break;
5583 case DBTYPES_DECIMAL: type = "decimal"; break;
5584 case DBTYPES_INTERVALDS: type = "intervalds"; break;
5585 case DBTYPES_INTERVALYM: type = "intervalym"; break;
5586 default:
5587 conv->error = "unsupported type for 'table_to_json'";
5588 conv->reason |= CONV_REASON_ARGS_FATAL;
5589 return NULL;
5590 }
5591 v = cson_value_null();
5592 goto annotate;
5593 }
5594 }
5595
5596 int tostr = 0; // 1->validate utf8 2->no validation
5597 int utf8_len;
5598 switch (dbtype) {
5599 case DBTYPES_LTABLE:
5600 if (is_array(L)) {
5601 type = "array";
5602 v = table_to_cson_array(L, lvl, conv);
5603 } else {
5604 type = "object";
5605 v = table_to_cson_object(L, lvl, conv);
5606 }
5607 break;
5608 case DBTYPES_LBOOLEAN:
5609 type = "bool";
5610 v = cson_value_new_bool(lua_toboolean(L, -1));
5611 break;
5612 case DBTYPES_LNUMBER:
5613 type = "number";
5614 dbl = lua_tonumber(L, -1);
5615 integer = lua_tointeger(L, -1);
5616 v = (dbl == integer) ? cson_value_new_integer(integer)
5617 : cson_value_new_double(dbl);

Callers 3

db_table_to_jsonFunction · 0.85
table_to_cson_arrayFunction · 0.85
table_to_cson_objectFunction · 0.85

Calls 15

lua_checkstackFunction · 0.85
lua_touserdataFunction · 0.85
cson_value_nullFunction · 0.85
is_arrayFunction · 0.85
table_to_cson_arrayFunction · 0.85
table_to_cson_objectFunction · 0.85
cson_value_new_boolFunction · 0.85
lua_tobooleanFunction · 0.85
lua_tonumberFunction · 0.85
lua_tointegerFunction · 0.85
cson_value_new_integerFunction · 0.85
cson_value_new_doubleFunction · 0.85

Tested by

no test coverage detected