diff options
Diffstat (limited to '')
| -rw-r--r-- | lua_cjson.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index 2a69699..875bdaf 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
| @@ -81,6 +81,7 @@ | |||
| 81 | #define DEFAULT_ENCODE_NUMBER_PRECISION 14 | 81 | #define DEFAULT_ENCODE_NUMBER_PRECISION 14 |
| 82 | #define DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT 1 | 82 | #define DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT 1 |
| 83 | #define DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT 0 | 83 | #define DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT 0 |
| 84 | #define DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH 1 | ||
| 84 | 85 | ||
| 85 | #ifdef DISABLE_INVALID_NUMBERS | 86 | #ifdef DISABLE_INVALID_NUMBERS |
| 86 | #undef DEFAULT_DECODE_INVALID_NUMBERS | 87 | #undef DEFAULT_DECODE_INVALID_NUMBERS |
| @@ -155,6 +156,7 @@ typedef struct { | |||
| 155 | int encode_number_precision; | 156 | int encode_number_precision; |
| 156 | int encode_keep_buffer; | 157 | int encode_keep_buffer; |
| 157 | int encode_empty_table_as_object; | 158 | int encode_empty_table_as_object; |
| 159 | int encode_escape_forward_slash; | ||
| 158 | 160 | ||
| 159 | int decode_invalid_numbers; | 161 | int decode_invalid_numbers; |
| 160 | int decode_max_depth; | 162 | int decode_max_depth; |
| @@ -406,6 +408,20 @@ static int json_cfg_decode_invalid_numbers(lua_State *l) | |||
| 406 | return 1; | 408 | return 1; |
| 407 | } | 409 | } |
| 408 | 410 | ||
| 411 | static int json_cfg_encode_escape_forward_slash(lua_State *l) | ||
| 412 | { | ||
| 413 | int ret; | ||
| 414 | json_config_t *cfg = json_arg_init(l, 1); | ||
| 415 | |||
| 416 | ret = json_enum_option(l, 1, &cfg->encode_escape_forward_slash, NULL, 1); | ||
| 417 | if (cfg->encode_escape_forward_slash) { | ||
| 418 | char2escape['/'] = "\\/"; | ||
| 419 | } else { | ||
| 420 | char2escape['/'] = NULL; | ||
| 421 | } | ||
| 422 | return ret; | ||
| 423 | } | ||
| 424 | |||
| 409 | static int json_destroy_config(lua_State *l) | 425 | static int json_destroy_config(lua_State *l) |
| 410 | { | 426 | { |
| 411 | json_config_t *cfg; | 427 | json_config_t *cfg; |
| @@ -442,6 +458,7 @@ static void json_create_config(lua_State *l) | |||
| 442 | cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION; | 458 | cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION; |
| 443 | cfg->encode_empty_table_as_object = DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT; | 459 | cfg->encode_empty_table_as_object = DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT; |
| 444 | cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT; | 460 | cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT; |
| 461 | cfg->encode_escape_forward_slash = DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH; | ||
| 445 | 462 | ||
| 446 | #if DEFAULT_ENCODE_KEEP_BUFFER > 0 | 463 | #if DEFAULT_ENCODE_KEEP_BUFFER > 0 |
| 447 | strbuf_init(&cfg->encode_buf, 0); | 464 | strbuf_init(&cfg->encode_buf, 0); |
| @@ -1457,6 +1474,7 @@ static int lua_cjson_new(lua_State *l) | |||
| 1457 | { "encode_keep_buffer", json_cfg_encode_keep_buffer }, | 1474 | { "encode_keep_buffer", json_cfg_encode_keep_buffer }, |
| 1458 | { "encode_invalid_numbers", json_cfg_encode_invalid_numbers }, | 1475 | { "encode_invalid_numbers", json_cfg_encode_invalid_numbers }, |
| 1459 | { "decode_invalid_numbers", json_cfg_decode_invalid_numbers }, | 1476 | { "decode_invalid_numbers", json_cfg_decode_invalid_numbers }, |
| 1477 | { "encode_escape_forward_slash", json_cfg_encode_escape_forward_slash }, | ||
| 1460 | { "new", lua_cjson_new }, | 1478 | { "new", lua_cjson_new }, |
| 1461 | { NULL, NULL } | 1479 | { NULL, NULL } |
| 1462 | }; | 1480 | }; |
