aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-12-14 00:57:57 +1030
committerMark Pulford <mark@kyne.com.au>2011-12-14 00:57:57 +1030
commit353784724505b23539aa693bd2aed3932493ed62 (patch)
treeca2f2c634fc3e4800dd93ba6f41f3e15830195c5
parent2487f7fa11a9c3c6d24948b4abc9a0e5468d1b1d (diff)
downloadlua-cjson-353784724505b23539aa693bd2aed3932493ed62.tar.gz
lua-cjson-353784724505b23539aa693bd2aed3932493ed62.tar.bz2
lua-cjson-353784724505b23539aa693bd2aed3932493ed62.zip
Remove quirks section from manual
Merge quirks section into: - Build overview (locales) - API docs Add API section for variables.
-rw-r--r--manual.txt129
1 files changed, 55 insertions, 74 deletions
diff --git a/manual.txt b/manual.txt
index 915c10a..ab08377 100644
--- a/manual.txt
+++ b/manual.txt
@@ -38,9 +38,33 @@ http://www.luajit.org[LuaJIT] to build.
38 38
39There are 3 build methods available: 39There are 3 build methods available:
40 40
41- Make: POSIX, OSX 41Make::
42- RPM: Various Linux distributions 42 POSIX (including Linux, BSD, Mac OSX & Solaris)
43- http://www.luarocks.org[LuaRocks]: POSIX, OSX, Windows 43RPM::
44 Linux
45LuaRocks::
46 POSIX (including Linux, BSD, Mac OSX & Solaris), Windows
47
48
49Build configuration overview
50~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
52Lua CJSON uses +strtod+(3) and +snprintf+(3) to perform numeric
53conversion as they are usually well supported, fast and bug free.
54
55To ensure JSON encoding/decoding works correctly for locales using
56comma decimal separators, Lua CJSON must be compiled with one of the
57following ++#define++s:
58
59USE_POSIX_USELOCALE::
60 Thread safe. Supported by Linux and Mac OSX. Recommended where available.
61USE_POSIX_SETLOCALE::
62 Works on all ANSI C platforms. May be used when thread-safety isn't required.
63
64Also available:
65
66USE_INTERNAL_ISINF::
67 Workaround for Solaris platforms missing isinf().
44 68
45 69
46Make 70Make
@@ -91,6 +115,7 @@ cd lua-cjson-1.0.4
91luarocks make 115luarocks make
92----------- 116-----------
93 117
118[NOTE]
94LuaRocks does not support platform specific configuration for Solaris. 119LuaRocks does not support platform specific configuration for Solaris.
95On Solaris, you may need to manually uncomment +USE_INTERNAL_ISINF+ in 120On Solaris, you may need to manually uncomment +USE_INTERNAL_ISINF+ in
96the rockspec before building this module. 121the rockspec before building this module.
@@ -99,8 +124,8 @@ See the http://luarocks.org/en/Documentation[LuaRocks documentation] for
99further details. 124further details.
100 125
101 126
102Lua API 127API (Functions)
103------- 128---------------
104 129
105Synopsis 130Synopsis
106~~~~~~~~ 131~~~~~~~~
@@ -156,6 +181,11 @@ data_json = '[ true, { "foo": "bar" } ]'
156data_obj = cjson.decode(data_json) 181data_obj = cjson.decode(data_json)
157------------ 182------------
158 183
184[CAUTION]
185Care must be taken when after decoding objects with numeric keys. Each
186numeric keys will be stored as a Lua +string+. Any code assuming type
187+number+ may break.
188
159 189
160cjson.encode 190cjson.encode
161~~~~~~~~~~~~ 191~~~~~~~~~~~~
@@ -177,7 +207,7 @@ JSON representation.
177- +string+ 207- +string+
178- +table+ 208- +table+
179 209
180The remaining Lua types cannot be serialised: 210The remaining Lua types will generate an error:
181 211
182- +function+ 212- +function+
183- +lightuserdata+ (non-NULL values) 213- +lightuserdata+ (non-NULL values)
@@ -217,6 +247,16 @@ example:
217[null,null,"data"] 247[null,null,"data"]
218------------------- 248-------------------
219 249
250Lua CJSON does not use metamethods when serialising tables.
251
252- +rawget+ is used to iterate over Lua arrays.
253- +next+ is used to iterate over Lua objects.
254
255JSON object keys are always strings. +cjson.encode+ can only handle
256table keys which are type +number+ or +string+. All other types will
257generate an error.
258
259
220[NOTE] 260[NOTE]
221Standards compliant JSON must be encapsulated in either an 261Standards compliant JSON must be encapsulated in either an
222object (+{}+) or an array (+[]+). Hence a table must be passed to 262object (+{}+) or an array (+[]+). Hence a table must be passed to
@@ -376,80 +416,21 @@ Disabled (decoding)::
376 All numbers supported by +strtod+(3) will be parsed. 416 All numbers supported by +strtod+(3) will be parsed.
377 417
378 418
379cjson.version 419API (Variables)
380~~~~~~~~~~~~~ 420---------------
381
382[source,lua]
383------------
384ver = cjson.version
385-- variable containing the package version (1.0.4)
386------------
387
388FIXME
389
390
391JSON and handling under Lua CJSON
392---------------------------------
393 421
394Nulls 422cjson.null
395~~~~~
396
397Lua CJSON decodes JSON +null+ as a Lua lightuserdata NULL pointer.
398
399As a convenience, +cjson.null+ is provided for comparison.
400
401
402Table keys
403~~~~~~~~~~ 423~~~~~~~~~~
404 424
405If all Lua table keys are type +number+ (not +string+), Lua CJSON will 425Lua CJSON decodes JSON +null+ as a Lua lightuserdata NULL pointer.
406encode the table as a JSON array. See 426+cjson.null+ can be used for comparison.
407<<sparse_arrays,cjson.encode_sparse_array>> above for more details.
408
409All other tables will be encoded as a JSON object.
410
411JSON requires that object keys must be type string. +cjson.encode+
412will convert numeric keys to a string, and other non-string types will
413generate an error.
414
415[CAUTION]
416=========
417Care must be taken when encoding/decoding objects which contain keys of type
418+number+.
419[source,lua]
420------------
421val = cjson.decode(cjson.encode{[1] = "1", a = "a"})
422-- Returns: { ["1"] = "1", ...
423-- NOT: { [1] = "1", ...
424------------
425=========
426
427Metamethods
428~~~~~~~~~~~
429
430Lua CJSON does not use metamethods when serialising tables.
431
432- +rawget+ is used to iterate over Lua arrays.
433- +next+ is used to iterate over Lua objects.
434
435
436Functions, Userdata, Threads
437~~~~~~~~~~~~~~~~~~~~~~~~~~~~
438
439Lua CJSON will generate an error if asked to serialise Lua functions,
440userdata, lightuserdata or threads.
441
442 427
443Locales
444~~~~~~~
445 428
446Lua CJSON uses +strtod+(3) and +snprintf+(3) to perform numeric conversion 429cjson.version
447as they are usually well supported, fast and bug free. 430~~~~~~~~~~~~~
448 431
449To ensure JSON encoding/decoding works correctly for locales using 432The version number of the Lua CJSON module in use can be found in
450comma decimal separators, Lua CJSON must be compiled with either 433+cjson.version+.
451+USE_POSIX_USELOCALE+ or +USE_POSIX_SETLOCALE+. See the +Makefile+ or the
452rockspec for details.
453 434
454 435
455[sect1] 436[sect1]