diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-12-15 21:40:57 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-12-15 21:40:57 +1030 |
commit | 35780fbe7d29e33abc0c18c9bcd5e91b6e08e31e (patch) | |
tree | b971ebbe6e684131f0aa004f96349bbbf3ed3820 | |
parent | 6b2578c5433d8afa46051bb57e3a3224603b264a (diff) | |
download | lua-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.txt | 48 |
1 files changed, 16 insertions, 32 deletions
@@ -72,17 +72,13 @@ Review and update the included Makefile to suit your platform. Next, | |||
72 | build and install the module: | 72 | build and install the module: |
73 | 73 | ||
74 | [source,sh] | 74 | [source,sh] |
75 | ----------- | ||
76 | make install | 75 | make install |
77 | ----------- | ||
78 | 76 | ||
79 | Or install manually: | 77 | Or install manually: |
80 | 78 | ||
81 | [source,sh] | 79 | [source,sh] |
82 | ----------- | ||
83 | make | 80 | make |
84 | cp cjson.so $your_lua_module_directory | 81 | cp cjson.so $your_lua_module_directory |
85 | ----------- | ||
86 | 82 | ||
87 | 83 | ||
88 | RPM | 84 | RPM |
@@ -93,10 +89,8 @@ the included RPM spec file. Install the +rpm-build+ package (or | |||
93 | similar) then: | 89 | similar) then: |
94 | 90 | ||
95 | [source,sh] | 91 | [source,sh] |
96 | ----------- | ||
97 | rpmbuild -tb lua-cjson-1.0devel.tar.gz | 92 | rpmbuild -tb lua-cjson-1.0devel.tar.gz |
98 | rpm -Uvh $newly_built_lua_cjson_rpm | 93 | rpm -Uvh $newly_built_lua_cjson_rpm |
99 | ----------- | ||
100 | 94 | ||
101 | 95 | ||
102 | LuaRocks | 96 | LuaRocks |
@@ -108,10 +102,8 @@ modules on a wide range of platforms (including Windows). | |||
108 | Extract the Lua CJSON source package into a directory and run: | 102 | Extract the Lua CJSON source package into a directory and run: |
109 | 103 | ||
110 | [source,sh] | 104 | [source,sh] |
111 | ----------- | ||
112 | cd lua-cjson-1.0devel | 105 | cd lua-cjson-1.0devel |
113 | luarocks make | 106 | luarocks make |
114 | ----------- | ||
115 | 107 | ||
116 | [NOTE] | 108 | [NOTE] |
117 | LuaRocks does not support platform specific configuration for Solaris. | 109 | LuaRocks does not support platform specific configuration for Solaris. |
@@ -172,16 +164,15 @@ By default, _invalid_ numbers (NaN, Infinity, Hexidecimal) will be | |||
172 | decoded. This default can be changed with | 164 | decoded. 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 | ------------ | 169 | json_text = '[ true, { "foo": "bar" } ]' |
178 | data_json = '[ true, { "foo": "bar" } ]' | 170 | value = cjson.decode(json_text) |
179 | data_obj = cjson.decode(data_json) | 171 | -- Returns: { true, { foo = "bar" } } |
180 | ------------ | ||
181 | 172 | ||
182 | [CAUTION] | 173 | [CAUTION] |
183 | Care must be taken when after decoding objects with numeric keys. Each | 174 | Care must be taken when after decoding JSON objects with numeric keys. Each |
184 | numeric keys will be stored as a Lua +string+. Any code assuming type | 175 | numeric 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 | |||
230 | integers (>0) keys of type +number+ will be encoded as a JSON array. | 221 | integers (>0) keys of type +number+ will be encoded as a JSON array. |
231 | All other tables will be encoded as a JSON object. | 222 | All other tables will be encoded as a JSON object. |
232 | 223 | ||
233 | Missing entries from sparse Lua arrays are encoded as +null+. For | 224 | Missing entries from sparse Lua arrays are encoded as +null+. |
234 | example: | ||
235 | 225 | ||
236 | .Lua input | 226 | .Example: Encoding a sparse array |
237 | [source,lua] | 227 | [source,lua] |
238 | ------------ | 228 | cjson.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 | ||
248 | Lua CJSON does not use metamethods when serialising tables. | 231 | Lua 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 | ------------ | 260 | value = { true, { foo = "bar" } } |
278 | data_obj = { true, { foo = "bar" } } | 261 | json_text = cjson.encode(value) |
279 | data_json = cjson.encode(data_obj) | 262 | -- Returns: '[true,{"foo":"bar"}]' |
280 | ------------ | ||
281 | 263 | ||
282 | 264 | ||
283 | cjson.encode_max_depth | 265 | cjson.encode_max_depth |
@@ -295,10 +277,12 @@ tables. | |||
295 | This check prevents a deeply nested or recursive data structure from | 277 | This check prevents a deeply nested or recursive data structure from |
296 | crashing the application. | 278 | crashing the application. |
297 | 279 | ||
298 | .Example | 280 | .Example: Recursive Lua tables |
299 | [source,lua] | 281 | [source,lua] |
300 | a = {}; b = { a }; a[1] = b | 282 | a = {}; b = { a }; a[1] = b |
301 | 283 | ||
284 | Once the maximum table depth has been reached Lua CJSON will throw an error. | ||
285 | |||
302 | 286 | ||
303 | cjson.encode_number_precision | 287 | cjson.encode_number_precision |
304 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 288 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |