Return cjson module table */
| 1378 | |
| 1379 | /* Return cjson module table */ |
| 1380 | static int lua_cjson_new(lua_State *l) |
| 1381 | { |
| 1382 | luaL_Reg reg[] = { |
| 1383 | { "encode", json_encode }, |
| 1384 | { "decode", json_decode }, |
| 1385 | { "encode_sparse_array", json_cfg_encode_sparse_array }, |
| 1386 | { "encode_max_depth", json_cfg_encode_max_depth }, |
| 1387 | { "decode_max_depth", json_cfg_decode_max_depth }, |
| 1388 | { "encode_number_precision", json_cfg_encode_number_precision }, |
| 1389 | { "encode_keep_buffer", json_cfg_encode_keep_buffer }, |
| 1390 | { "encode_invalid_numbers", json_cfg_encode_invalid_numbers }, |
| 1391 | { "decode_invalid_numbers", json_cfg_decode_invalid_numbers }, |
| 1392 | { "new", lua_cjson_new }, |
| 1393 | { NULL, NULL } |
| 1394 | }; |
| 1395 | |
| 1396 | /* Initialise number conversions */ |
| 1397 | fpconv_init(); |
| 1398 | |
| 1399 | /* cjson module table */ |
| 1400 | lua_newtable(l); |
| 1401 | |
| 1402 | /* Register functions with config data as upvalue */ |
| 1403 | json_create_config(l); |
| 1404 | luaL_setfuncs(l, reg, 1); |
| 1405 | |
| 1406 | /* Set cjson.null */ |
| 1407 | lua_pushlightuserdata(l, NULL); |
| 1408 | lua_setfield(l, -2, "null"); |
| 1409 | |
| 1410 | /* Set module name / version fields */ |
| 1411 | lua_pushliteral(l, CJSON_MODNAME); |
| 1412 | lua_setfield(l, -2, "_NAME"); |
| 1413 | lua_pushliteral(l, CJSON_VERSION); |
| 1414 | lua_setfield(l, -2, "_VERSION"); |
| 1415 | |
| 1416 | return 1; |
| 1417 | } |
| 1418 | |
| 1419 | /* Return cjson.safe module table */ |
| 1420 | static int lua_cjson_safe_new(lua_State *l) |
no test coverage detected