MCPcopy Create free account
hub / github.com/axmolengine/axmol / json_create_config

Function json_create_config

3rdparty/lua/lua-cjson/lua_cjson.c:384–455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382}
383
384static void json_create_config(lua_State *l)
385{
386 json_config_t *cfg;
387 int i;
388
389 cfg = (json_config_t *)lua_newuserdata(l, sizeof(*cfg));
390
391 /* Create GC method to clean up strbuf */
392 lua_newtable(l);
393 lua_pushcfunction(l, json_destroy_config);
394 lua_setfield(l, -2, "__gc");
395 lua_setmetatable(l, -2);
396
397 cfg->encode_sparse_convert = DEFAULT_SPARSE_CONVERT;
398 cfg->encode_sparse_ratio = DEFAULT_SPARSE_RATIO;
399 cfg->encode_sparse_safe = DEFAULT_SPARSE_SAFE;
400 cfg->encode_max_depth = DEFAULT_ENCODE_MAX_DEPTH;
401 cfg->decode_max_depth = DEFAULT_DECODE_MAX_DEPTH;
402 cfg->encode_invalid_numbers = DEFAULT_ENCODE_INVALID_NUMBERS;
403 cfg->decode_invalid_numbers = DEFAULT_DECODE_INVALID_NUMBERS;
404 cfg->encode_keep_buffer = DEFAULT_ENCODE_KEEP_BUFFER;
405 cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION;
406
407#if DEFAULT_ENCODE_KEEP_BUFFER > 0
408 strbuf_init(&cfg->encode_buf, 0);
409#endif
410
411 /* Decoding init */
412
413 /* Tag all characters as an error */
414 for (i = 0; i < 256; i++)
415 cfg->ch2token[i] = T_ERROR;
416
417 /* Set tokens that require no further processing */
418 cfg->ch2token['{'] = T_OBJ_BEGIN;
419 cfg->ch2token['}'] = T_OBJ_END;
420 cfg->ch2token['['] = T_ARR_BEGIN;
421 cfg->ch2token[']'] = T_ARR_END;
422 cfg->ch2token[','] = T_COMMA;
423 cfg->ch2token[':'] = T_COLON;
424 cfg->ch2token['\0'] = T_END;
425 cfg->ch2token[' '] = T_WHITESPACE;
426 cfg->ch2token['\t'] = T_WHITESPACE;
427 cfg->ch2token['\n'] = T_WHITESPACE;
428 cfg->ch2token['\r'] = T_WHITESPACE;
429
430 /* Update characters that require further processing */
431 cfg->ch2token['f'] = T_UNKNOWN; /* false? */
432 cfg->ch2token['i'] = T_UNKNOWN; /* inf, ininity? */
433 cfg->ch2token['I'] = T_UNKNOWN;
434 cfg->ch2token['n'] = T_UNKNOWN; /* null, nan? */
435 cfg->ch2token['N'] = T_UNKNOWN;
436 cfg->ch2token['t'] = T_UNKNOWN; /* true? */
437 cfg->ch2token['"'] = T_UNKNOWN; /* string? */
438 cfg->ch2token['+'] = T_UNKNOWN; /* number? */
439 cfg->ch2token['-'] = T_UNKNOWN;
440 for (i = 0; i < 10; i++)
441 cfg->ch2token['0' + i] = T_UNKNOWN;

Callers 1

lua_cjson_newFunction · 0.85

Calls 3

lua_setfieldFunction · 0.85
lua_setmetatableFunction · 0.85
strbuf_initFunction · 0.85

Tested by

no test coverage detected