diff options
Diffstat (limited to 'manual.txt')
-rw-r--r-- | manual.txt | 61 |
1 files changed, 47 insertions, 14 deletions
@@ -16,8 +16,6 @@ Lua CJSON provides fast JSON parsing and encoding support for Lua. | |||
16 | 16 | ||
17 | .Caveats | 17 | .Caveats |
18 | - UTF-16 and UTF-32 are not supported. | 18 | - UTF-16 and UTF-32 are not supported. |
19 | - Multi-threading within a single Lua state is not supported | ||
20 | (+lua_lock+ / +lua_unlock+). | ||
21 | 19 | ||
22 | Lua CJSON is covered by the MIT license. Review the file +LICENSE+ for | 20 | Lua CJSON is covered by the MIT license. Review the file +LICENSE+ for |
23 | details. | 21 | details. |
@@ -32,7 +30,7 @@ comments. | |||
32 | Installation Methods | 30 | Installation Methods |
33 | -------------------- | 31 | -------------------- |
34 | 32 | ||
35 | Lua CJSON requires either http://www.lua.org[Lua] or | 33 | Lua CJSON requires either http://www.lua.org[Lua] 5.1, Lua 5.2, or |
36 | http://www.luajit.org[LuaJIT] to build. | 34 | http://www.luajit.org[LuaJIT] to build. |
37 | 35 | ||
38 | There are 4 build methods available: | 36 | There are 4 build methods available: |
@@ -44,11 +42,13 @@ RPM:: Linux | |||
44 | LuaRocks:: Unix, Windows | 42 | LuaRocks:: Unix, Windows |
45 | 43 | ||
46 | 44 | ||
47 | Build options (#define) | 45 | Build Options (#define) |
48 | ~~~~~~~~~~~~~~~~~~~~~~~ | 46 | ~~~~~~~~~~~~~~~~~~~~~~~ |
49 | 47 | ||
50 | [horizontal] | 48 | [horizontal] |
51 | USE_INTERNAL_ISINF:: Workaround for Solaris platforms missing isinf(). | 49 | USE_INTERNAL_ISINF:: Workaround for Solaris platforms missing isinf(). |
50 | DISABLE_CJSON_GLOBAL:: Do not store module table in global "cjson" | ||
51 | variable. | ||
52 | 52 | ||
53 | 53 | ||
54 | Make | 54 | Make |
@@ -125,9 +125,9 @@ Synopsis | |||
125 | 125 | ||
126 | [source,lua] | 126 | [source,lua] |
127 | ------------ | 127 | ------------ |
128 | require "cjson" | 128 | -- Module initalisation methods |
129 | -- Or: | ||
130 | local cjson = require "cjson" | 129 | local cjson = require "cjson" |
130 | local cjson2 = cjson.new() | ||
131 | 131 | ||
132 | -- Translate Lua value to/from JSON | 132 | -- Translate Lua value to/from JSON |
133 | text = cjson.encode(value) | 133 | text = cjson.encode(value) |
@@ -141,6 +141,34 @@ keep = cjson.encode_keep_buffer([keep]) | |||
141 | ------------ | 141 | ------------ |
142 | 142 | ||
143 | 143 | ||
144 | Module Instantiation | ||
145 | ~~~~~~~~~~~~~~~~~~~~ | ||
146 | |||
147 | [source,lua] | ||
148 | ------------ | ||
149 | local cjson = require "cjson" | ||
150 | local cjson2 = cjson.new() | ||
151 | ------------ | ||
152 | |||
153 | Lua CJSON can be loaded via +require+. A global +cjson+ table is | ||
154 | registered under Lua 5.1 to maintain backward compatibility. Lua CJSON | ||
155 | does not register a global table under Lua 5.2 since this practice is | ||
156 | discouraged. | ||
157 | |||
158 | +cjson.new+ can be used to instantiate an independent copy of the Lua | ||
159 | CJSON module. The new module has a separate persistent encoding | ||
160 | buffer, and default settings. | ||
161 | |||
162 | Lua CJSON can support Lua implementations using multiple pre-emptive | ||
163 | threads within a single Lua state provided the persistent encoding | ||
164 | buffer is not shared. This can be achieved by one of the following | ||
165 | methods: | ||
166 | |||
167 | - Disabling the persistent encoding buffer with +encode_keep_buffer+. | ||
168 | - Ensuring only a single thread calls +encode+ at a time. | ||
169 | - Using a separate +cjson+ instantiation per pre-emptive thread. | ||
170 | |||
171 | |||
144 | decode | 172 | decode |
145 | ~~~~~~ | 173 | ~~~~~~ |
146 | 174 | ||
@@ -423,6 +451,18 @@ Disabled for decoding:: All numbers supported by +strtod+(3) will be parsed. | |||
423 | API (Variables) | 451 | API (Variables) |
424 | --------------- | 452 | --------------- |
425 | 453 | ||
454 | _NAME | ||
455 | ~~~~~ | ||
456 | |||
457 | The name of the Lua CJSON module (+"cjson"+). | ||
458 | |||
459 | |||
460 | _VERSION | ||
461 | ~~~~~~~~ | ||
462 | |||
463 | The version number of the Lua CJSON module (Eg, +"1.0devel"+). | ||
464 | |||
465 | |||
426 | null | 466 | null |
427 | ~~~~ | 467 | ~~~~ |
428 | 468 | ||
@@ -430,13 +470,6 @@ Lua CJSON decodes JSON +null+ as a Lua +lightuserdata+ NULL pointer. | |||
430 | +cjson.null+ is provided for comparison. | 470 | +cjson.null+ is provided for comparison. |
431 | 471 | ||
432 | 472 | ||
433 | version | ||
434 | ~~~~~~~ | ||
435 | |||
436 | The version number of the Lua CJSON module in use can be found in | ||
437 | +cjson.version+. | ||
438 | |||
439 | |||
440 | [sect1] | 473 | [sect1] |
441 | References | 474 | References |
442 | ---------- | 475 | ---------- |
@@ -445,4 +478,4 @@ References | |||
445 | - http://www.json.org/[JSON website] | 478 | - http://www.json.org/[JSON website] |
446 | 479 | ||
447 | 480 | ||
448 | // vi:tw=70: | 481 | // vi:ft=asciidoc tw=70: |