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

Function lua_cjson_new

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:1347–1384  ·  view source on GitHub ↗

Return cjson module table */

Source from the content-addressed store, hash-verified

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

Callers 2

lua_cjson_safe_newFunction · 0.85
luaopen_cjsonFunction · 0.85

Calls 3

json_create_configFunction · 0.85
luaL_setfuncsFunction · 0.85
fpconv_initFunction · 0.70

Tested by

no test coverage detected