MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / lua_cjson_new

Function lua_cjson_new

deps/lua/src/lua_cjson.c:1344–1381  ·  view source on GitHub ↗

Return cjson module table */

Source from the content-addressed store, hash-verified

1342
1343/* Return cjson module table */
1344static int lua_cjson_new(lua_State *l)
1345{
1346 luaL_Reg reg[] = {
1347 { "encode", json_encode },
1348 { "decode", json_decode },
1349 { "encode_sparse_array", json_cfg_encode_sparse_array },
1350 { "encode_max_depth", json_cfg_encode_max_depth },
1351 { "decode_max_depth", json_cfg_decode_max_depth },
1352 { "encode_number_precision", json_cfg_encode_number_precision },
1353 { "encode_keep_buffer", json_cfg_encode_keep_buffer },
1354 { "encode_invalid_numbers", json_cfg_encode_invalid_numbers },
1355 { "decode_invalid_numbers", json_cfg_decode_invalid_numbers },
1356 { "new", lua_cjson_new },
1357 { NULL, NULL }
1358 };
1359
1360 /* Initialise number conversions */
1361 fpconv_init();
1362
1363 /* cjson module table */
1364 lua_newtable(l);
1365
1366 /* Register functions with config data as upvalue */
1367 json_create_config(l);
1368 luaL_setfuncs(l, reg, 1);
1369
1370 /* Set cjson.null */
1371 lua_pushlightuserdata(l, NULL);
1372 lua_setfield(l, -2, "null");
1373
1374 /* Set module name / version fields */
1375 lua_pushliteral(l, CJSON_MODNAME);
1376 lua_setfield(l, -2, "_NAME");
1377 lua_pushliteral(l, CJSON_VERSION);
1378 lua_setfield(l, -2, "_VERSION");
1379
1380 return 1;
1381}
1382
1383/* Return cjson.safe module table */
1384static int lua_cjson_safe_new(lua_State *l)

Callers 2

lua_cjson_safe_newFunction · 0.85
luaopen_cjsonFunction · 0.85

Calls 5

json_create_configFunction · 0.85
luaL_setfuncsFunction · 0.85
lua_pushlightuserdataFunction · 0.85
lua_setfieldFunction · 0.85
fpconv_initFunction · 0.70

Tested by

no test coverage detected