aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-12-15 21:40:57 +1030
committerMark Pulford <mark@kyne.com.au>2011-12-15 21:40:57 +1030
commit35780fbe7d29e33abc0c18c9bcd5e91b6e08e31e (patch)
treeb971ebbe6e684131f0aa004f96349bbbf3ed3820
parent6b2578c5433d8afa46051bb57e3a3224603b264a (diff)
downloadlua-cjson-35780fbe7d29e33abc0c18c9bcd5e91b6e08e31e.tar.gz
lua-cjson-35780fbe7d29e33abc0c18c9bcd5e91b6e08e31e.tar.bz2
lua-cjson-35780fbe7d29e33abc0c18c9bcd5e91b6e08e31e.zip
Update examples in documentation
- Remove block quotes - Add titles
-rw-r--r--manual.txt48
1 files changed, 16 insertions, 32 deletions
diff --git a/manual.txt b/manual.txt
index 37d8229..dc3c26f 100644
--- a/manual.txt
+++ b/manual.txt
@@ -72,17 +72,13 @@ Review and update the included Makefile to suit your platform. Next,
72build and install the module: 72build and install the module:
73 73
74[source,sh] 74[source,sh]
75-----------
76make install 75make install
77-----------
78 76
79Or install manually: 77Or install manually:
80 78
81[source,sh] 79[source,sh]
82-----------
83make 80make
84cp cjson.so $your_lua_module_directory 81cp cjson.so $your_lua_module_directory
85-----------
86 82
87 83
88RPM 84RPM
@@ -93,10 +89,8 @@ the included RPM spec file. Install the +rpm-build+ package (or
93similar) then: 89similar) then:
94 90
95[source,sh] 91[source,sh]
96-----------
97rpmbuild -tb lua-cjson-1.0devel.tar.gz 92rpmbuild -tb lua-cjson-1.0devel.tar.gz
98rpm -Uvh $newly_built_lua_cjson_rpm 93rpm -Uvh $newly_built_lua_cjson_rpm
99-----------
100 94
101 95
102LuaRocks 96LuaRocks
@@ -108,10 +102,8 @@ modules on a wide range of platforms (including Windows).
108Extract the Lua CJSON source package into a directory and run: 102Extract the Lua CJSON source package into a directory and run:
109 103
110[source,sh] 104[source,sh]
111-----------
112cd lua-cjson-1.0devel 105cd lua-cjson-1.0devel
113luarocks make 106luarocks make
114-----------
115 107
116[NOTE] 108[NOTE]
117LuaRocks does not support platform specific configuration for Solaris. 109LuaRocks does not support platform specific configuration for Solaris.
@@ -172,16 +164,15 @@ By default, _invalid_ numbers (NaN, Infinity, Hexidecimal) will be
172decoded. This default can be changed with 164decoded. This default can be changed with
173+cjson.refuse_invalid_numbers+. 165+cjson.refuse_invalid_numbers+.
174 166
175.Example: decoding 167.Example: Decoding
176[source,lua] 168[source,lua]
177------------ 169json_text = '[ true, { "foo": "bar" } ]'
178data_json = '[ true, { "foo": "bar" } ]' 170value = cjson.decode(json_text)
179data_obj = cjson.decode(data_json) 171-- Returns: { true, { foo = "bar" } }
180------------
181 172
182[CAUTION] 173[CAUTION]
183Care must be taken when after decoding objects with numeric keys. Each 174Care must be taken when after decoding JSON objects with numeric keys. Each
184numeric keys will be stored as a Lua +string+. Any code assuming type 175numeric key will be stored as a Lua +string+. Any code assuming type
185+number+ may break. 176+number+ may break.
186 177
187 178
@@ -230,20 +221,12 @@ as a JSON array or an object. A Lua table which only has positive
230integers (>0) keys of type +number+ will be encoded as a JSON array. 221integers (>0) keys of type +number+ will be encoded as a JSON array.
231All other tables will be encoded as a JSON object. 222All other tables will be encoded as a JSON object.
232 223
233Missing entries from sparse Lua arrays are encoded as +null+. For 224Missing entries from sparse Lua arrays are encoded as +null+.
234example:
235 225
236.Lua input 226.Example: Encoding a sparse array
237[source,lua] 227[source,lua]
238------------ 228cjson.encode({ [3] = "data" })
239{ [3] = "data" } 229-- Returns: '[null,null,"data"]'
240------------
241
242.JSON output
243[source,javascript]
244-------------------
245[null,null,"data"]
246-------------------
247 230
248Lua CJSON does not use metamethods when serialising tables. 231Lua CJSON does not use metamethods when serialising tables.
249 232
@@ -274,10 +257,9 @@ These defaults can be changed with:
274 257
275.Example: encoding 258.Example: encoding
276[source,lua] 259[source,lua]
277------------ 260value = { true, { foo = "bar" } }
278data_obj = { true, { foo = "bar" } } 261json_text = cjson.encode(value)
279data_json = cjson.encode(data_obj) 262-- Returns: '[true,{"foo":"bar"}]'
280------------
281 263
282 264
283cjson.encode_max_depth 265cjson.encode_max_depth
@@ -295,10 +277,12 @@ tables.
295This check prevents a deeply nested or recursive data structure from 277This check prevents a deeply nested or recursive data structure from
296crashing the application. 278crashing the application.
297 279
298.Example 280.Example: Recursive Lua tables
299[source,lua] 281[source,lua]
300a = {}; b = { a }; a[1] = b 282a = {}; b = { a }; a[1] = b
301 283
284Once the maximum table depth has been reached Lua CJSON will throw an error.
285
302 286
303cjson.encode_number_precision 287cjson.encode_number_precision
304~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 288~~~~~~~~~~~~~~~~~~~~~~~~~~~~~