diff options
Diffstat (limited to 'lua_cjson.c')
-rw-r--r-- | lua_cjson.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index de67766..379ea23 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
@@ -1,25 +1,41 @@ | |||
1 | /* Lua JSON routines | 1 | /* CJSON - JSON support for Lua |
2 | * | ||
3 | * Copyright (c) 2010-2011 Mark Pulford <mark@kyne.com.au> | ||
4 | * | ||
5 | * Permission is hereby granted, free of charge, to any person obtaining | ||
6 | * a copy of this software and associated documentation files (the | ||
7 | * "Software"), to deal in the Software without restriction, including | ||
8 | * without limitation the rights to use, copy, modify, merge, publish, | ||
9 | * distribute, sublicense, and/or sell copies of the Software, and to | ||
10 | * permit persons to whom the Software is furnished to do so, subject to | ||
11 | * the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice shall be | ||
14 | * included in all copies or substantial portions of the Software. | ||
15 | * | ||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
2 | */ | 23 | */ |
3 | 24 | ||
4 | /* Caveats: | 25 | /* Caveats: |
5 | * - Assumes strings are valid UTF-8 and mostly treats them as opaque | 26 | * - JSON "null" values are represented as lightuserdata since Lua |
6 | * binary data. Will not throw an exception on bad data. | 27 | * tables cannot contain "nil". Compare with cjson.null. |
7 | * - Will decode \uXXXX escapes, but leaves high codepoints as UTF-8 | 28 | * - Only standard JSON escapes and \u0000 are used when encoding |
8 | * when encoding. | 29 | * JSON. Most unprintable characters are not escaped. |
9 | * - JSON "null" values are represented as lightuserdata. Compare with | 30 | * - Invalid UTF-8 characters are not detected and will be passed |
10 | * json.null. | 31 | * untouched. |
11 | * - Parsing comments is not supported. According to json.org, this isn't | 32 | * - Cannot parse NaN/Inf numbers when strict_numbers has been disabled. |
12 | * part of the spec. | 33 | * - Javascript comments are not part of the JSON spec, and are not |
13 | * - Parser accepts number formats beyond the JSON spec. | 34 | * supported. |
14 | * | 35 | * |
15 | * Note: lua_json_decode() probably spends significant time rehashing | 36 | * Note: Decoding is slower than encoding. Lua probably spends |
16 | * tables since it is difficult to know their size ahead of time. | 37 | * significant time rehashing tables when parsing JSON since it is |
17 | * Earlier JSON libaries didn't have this problem but the intermediate | 38 | * difficult to know object/array sizes ahead of time. |
18 | * storage (and their implementations) were much slower anyway.. | ||
19 | */ | ||
20 | |||
21 | /* FIXME: | ||
22 | * - Option to encode non-printable characters? Only \" \\ are required | ||
23 | */ | 39 | */ |
24 | 40 | ||
25 | #include <assert.h> | 41 | #include <assert.h> |