webmcp
view libraries/json/json.autodoc.lua @ 194:654ddbcc49d0
Bugfix in autodoc.lua; Added documentation for JSON library; json.import(...) returns json.null for "null" on top-level
| author | jbe | 
|---|---|
| date | Mon Aug 11 17:38:12 2014 +0200 (2014-08-11) | 
| parents | |
| children | 31f775ea5e24 | 
 line source
     2 --[[--
     3 json.null
     5 A special marker to be used to write a value of null to a JSON object or JSON array. The marker is only used for setting a value to null: when reading null values from a JSON object or JSON array via the index operator, via json.get(...), or via pairs(...) or ipairs(...), then the null values will always read as nil.
     7 --]]--
     8 -- implemented as lightuserdata in json.c
     9 -- pointing to field "nullmark" of json_lightuserdata struct
    10 --//--
    13 --[[--
    14 obj =             -- a new JSON object
    15 json.object{
    16   key1 = value1,  -- key value pair to be set in JSON object
    17   key2 = value2,  -- another key value pair to be set in JSON object
    18   ...
    19 }
    21 Converts a Lua table (or any other value with a __pairs metamethod) to a JSON object. The argument is never modified. May also be called without arguments to create an empty JSON object. All JSON objects support iteration using pairs(...).
    23 --]]--
    24 -- implemented as in json.c as
    25 -- static int json_object(lua_State *L)
    26 --//--
    29 --[[--
    30 ary =        -- a new JSON array
    31 json.array{
    32   value1,    -- first value to be set in JSON array
    33   value2,    -- second value to be set in JSON array
    34   ...
    35 }
    37 Converts a Lua table (or any other value with an __ipairs metamethod) to a JSON array. The argument is never modified. May also be called without arguments to create an empty JSON array. All JSON arrays support iteration using ipairs(...).
    39 --]]--
    40 -- implemented in json.c as
    41 -- static int json_object(lua_State *L)
    42 --//--
    45 --[[--
    46 parsed_document,           -- parsed value, json.null for null values, or nil in case of error
    47 errmsg =                   -- error message if document could not be parsed
    48 json.import(
    49   json_document_as_string  -- string to be parsed
    50 )
    52 Parses a JSON document. Returns a string, a number, a boolean, json.null, or a JSON object or JSON array as returned by json.object{...} or json.array{...} respectively. The special value json.null is only returned if the top level value is null; null values within the document always read as nil! (see json.null)
    54 --]]--
    55 -- implemented in json.c as
    56 -- static int json_import(lua_State *L)
    57 --//--
    60 --[[--
    61 value =      -- value that has been read, or nil if path does not exist
    62 json.get(
    63   document,  -- JSON value (usually object or array)
    64   key1,      -- first path element (e.g. a string key to descent into an object)
    65   key2,      -- second path element (e.g. an integer key to descent into an array)
    66   ...,
    67   last_key   -- last path element
    68 )
    70 Reads a value from a JSON document by following a given path that may contain string keys (to descent into an object) or integer keys (to descent into an array). A JSON value of null is returned as nil. This function also works on plain Lua tables instead of JSON documents.
    72 Examples:
    73 json.get(json.import('{"a":{"b":3}}'), "a", "b") == 3
    74 json.get(json.import('{"a":{"b":3}}'), "c", "d") == nil
    75 json.get(json.import('{"n":null}'), "n") == nil
    77 --]]--
    78 -- implemented in json.c as
    79 -- static int json_get(lua_State *L)
    80 --//--
    83 --[[--
    84 type_string_or_nil  -- "object", "array", "string", "number", "boolean", "null", string "nil", or nil
    85 json.get(
    86   document,         -- a JSON value (usually object or array)
    87   key1,             -- first path element (e.g. a string key to descent into an object)
    88   key2,             -- second path element (e.g. an integer key to descent into an array)
    89   ...,
    90   last_key          -- last path element
    91 )
    93 Determines the type of a value in a JSON document by following a given path that may contain string keys (to descent into an object) or integer keys (to descent into an array). If the path but its last path element could be followed, then the string "nil" is returned. If the previous path elements could not be followed, then nil itself is returned. Otherwise the type of the value is returned, whereas the string "null" indicates a JSON null value. This function also works on plain Lua tables instead of JSON documents.
    95 Examples:
    96 json.type(json.import('{"a":{"b":3}}'), "a", "b") == 3
    97 json.type(json.import('{"a":{"b":null}}'), "a", "b") == "null"
    98 json.type(json.import('{"a":{"b":null}}'), "a", "c") == "nil"
    99 json.type(json.import('{"a":{"b":null}}'), "d", "c") == nil
   101 --]]--
   102 -- implemented in json.c as
   103 -- static int json_type(lua_State *L)
   104 --//--
   107 --[[--
   108 document =
   109 json.set(
   110   document,
   111   value,
   112   key1,      -- first path element (e.g. a string key to descent into an object)
   113   key2,      -- second path element (e.g. an integer key to descent into an array)
   114   ...
   115   last_key   -- last path element
   116 )
   118 Sets a value in a JSON document by following a given path that may contain string keys (to descent into an object) or integer keys (to descent into an array). If the path does not exist (or contains objects where arrays are expected or vice versa), then the necessary intermediate JSON objects or JSON arrays are created. This function also works on plain Lua tables but will create JSON objects or arrays where necessary.
   120 --]]--
   121 -- implemented in json.c as
   122 -- static int json_set(lua_State *L)
   123 --//--
   126 --[[--
   127 encoded_document =  -- encoded JSON document as string
   128 json.export(
   129   document,         -- a JSON value (usually object or array)
   130   indentation       -- indentation string to use for pretty printing, or true for two spaces
   131 )
   133 Encodes a JSON document. Since the order of object keys is deterministic, this function may also be used to compare two JSON documents for (deep) equality: json.export(a) == json.export(b). If the indentation argument is nil or false, then pretty printing is disabled.
   135 --]]--
   136 -- implemented in json.c as
   137 -- static int json_export(lua_State *L)
   138 --//--
