diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/luci-lib-ip/src/ip.luadoc | 16 | ||||
-rw-r--r-- | libs/luci-lib-json/luasrc/json.luadoc | 2 | ||||
-rw-r--r-- | libs/luci-lib-jsonc/src/jsonc.c | 81 | ||||
-rw-r--r-- | libs/luci-lib-jsonc/src/jsonc.luadoc | 14 | ||||
-rw-r--r-- | libs/luci-lib-rpcc/luasrc/rpcc.luadoc | 2 | ||||
-rw-r--r-- | libs/luci-lib-rpcc/luasrc/rpcc/ruci.luadoc | 2 |
6 files changed, 101 insertions, 16 deletions
diff --git a/libs/luci-lib-ip/src/ip.luadoc b/libs/luci-lib-ip/src/ip.luadoc index 00738832c4..e32ae72f40 100644 --- a/libs/luci-lib-ip/src/ip.luadoc +++ b/libs/luci-lib-ip/src/ip.luadoc @@ -42,10 +42,10 @@ if the given optional netmask is of a different family. containing a prefix size between `0` and `32` bit. Overrides mask embedded in the first argument if specified. (optional) @return A `luci.ip.cidr` object representing the given IPv4 range. -@usage `addr = luci.ip.new("10.24.0.1/24") -addr = luci.ip.new("10.24.0.1/255.255.255.0") -addr = luci.ip.new("10.24.0.1", "255.255.255.0") -- separate netmask -addr = luci.ip.new("10.24.0.1/24", 16) -- override netmask` +@usage `addr = luci.ip.IPv4("10.24.0.1/24") +addr = luci.ip.IPv4("10.24.0.1/255.255.255.0") +addr = luci.ip.IPv4("10.24.0.1", "255.255.255.0") -- separate netmask +addr = luci.ip.IPv4("10.24.0.1/24", 16) -- override netmask` @see IPv6 ]] @@ -62,10 +62,10 @@ if the given optional netmask is of a different family. containing a prefix size between `0` and `128` bit. Overrides mask embedded in the first argument if specified. (optional) @return A `luci.ip.cidr` object representing the given IPv6 range. -@usage `addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64") -addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::") -addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::") -addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask` +@usage `addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64") +addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::") +addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::") +addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask` @see IPv4 ]] diff --git a/libs/luci-lib-json/luasrc/json.luadoc b/libs/luci-lib-json/luasrc/json.luadoc index d48dba13b9..37f97d25f2 100644 --- a/libs/luci-lib-json/luasrc/json.luadoc +++ b/libs/luci-lib-json/luasrc/json.luadoc @@ -2,8 +2,8 @@ LuCI JSON-Library @cstyle instance -module "luci.json" ]] +module "luci.json" ---[[ Directly decode a JSON string diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c index 49cb21f5bc..ef11101660 100644 --- a/libs/luci-lib-jsonc/src/jsonc.c +++ b/libs/luci-lib-jsonc/src/jsonc.c @@ -106,6 +106,7 @@ static int json_stringify(lua_State *L) flags |= JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED; lua_pushstring(L, json_object_to_json_string_ext(obj, flags)); + json_object_put(obj); return 1; } @@ -222,7 +223,7 @@ static int _lua_test_array(lua_State *L, int index) out: lua_pop(L, 2); - return 0; + return -1; } /* check for holes */ @@ -254,7 +255,7 @@ static struct json_object * _lua_to_json(lua_State *L, int index) case LUA_TTABLE: max = _lua_test_array(L, index); - if (max > 0) + if (max >= 0) { obj = json_object_new_array(); @@ -286,8 +287,9 @@ static struct json_object * _lua_to_json(lua_State *L, int index) lua_pushvalue(L, -2); key = lua_tostring(L, -1); - json_object_object_add(obj, key, - _lua_to_json(L, lua_gettop(L) - 1)); + if (key) + json_object_object_add(obj, key, + _lua_to_json(L, lua_gettop(L) - 1)); lua_pop(L, 2); } @@ -326,6 +328,76 @@ static int json_parse_set(lua_State *L) return 0; } +static int json_parse_sink_closure(lua_State *L) +{ + bool finished = lua_toboolean(L, lua_upvalueindex(2)); + if (lua_isnil(L, 1)) + { + // no more data available + if (finished) + { + // we were finished parsing + lua_pushboolean(L, true); + return 1; + } + else + { + lua_pushnil(L); + lua_pushstring(L, "Incomplete JSON data"); + return 2; + } + } + else + { + if (finished) + { + lua_pushnil(L); + lua_pushstring(L, "Unexpected data after complete JSON object"); + return 2; + } + else + { + // luci.jsonc.parser.chunk() + lua_pushcfunction(L, json_parse_chunk); + // parser object from closure + lua_pushvalue(L, lua_upvalueindex(1)); + // chunk + lua_pushvalue(L, 1); + lua_call(L, 2, 2); + + if (lua_isnil(L, -2)) + { + // an error occurred, leave (nil, errmsg) on the stack and return it + return 2; + } + else if (lua_toboolean(L, -2)) + { + // finished reading, set finished=true and return nil to prevent further input + lua_pop(L, 2); + lua_pushboolean(L, true); + lua_replace(L, lua_upvalueindex(2)); + lua_pushnil(L); + return 1; + } + else + { + // not finished reading, return true + lua_pop(L, 2); + lua_pushboolean(L, true); + return 1; + } + } + } +} + +static int json_parse_sink(lua_State *L) +{ + luaL_checkudata(L, 1, LUCI_JSONC_PARSER); + lua_pushboolean(L, false); + lua_pushcclosure(L, json_parse_sink_closure, 2); + return 1; +} + static int json_tostring(lua_State *L) { struct json_state *s = luaL_checkudata(L, 1, LUCI_JSONC_PARSER); @@ -365,6 +437,7 @@ static const luaL_reg jsonc_parser_methods[] = { { "parse", json_parse_chunk }, { "get", json_parse_get }, { "set", json_parse_set }, + { "sink", json_parse_sink }, { "stringify", json_tostring }, { "__gc", json_gc }, diff --git a/libs/luci-lib-jsonc/src/jsonc.luadoc b/libs/luci-lib-jsonc/src/jsonc.luadoc index 2ee9cebdc8..720b17d1eb 100644 --- a/libs/luci-lib-jsonc/src/jsonc.luadoc +++ b/libs/luci-lib-jsonc/src/jsonc.luadoc @@ -121,10 +121,22 @@ parser:set({ "some", "data" })` ]] ---[[ -Serialize current parser state as JSON. +Generate an ltn12-compatible sink. @class function @sort 4 +@name parser.sink +@return Returns a function that can be used as an ltn12 sink. +@usage `parser = luci.jsonc.new() +ltn12.pump.all(ltn12.source.file(io.input()), parser:sink()) +print(parser:get())` +]] + +---[[ +Serialize current parser state as JSON. + +@class function +@sort 5 @name parser.stringify @param pretty A boolean value indicating whether the resulting JSON should be pretty printed. @return Returns the serialized JSON data of this parser instance. diff --git a/libs/luci-lib-rpcc/luasrc/rpcc.luadoc b/libs/luci-lib-rpcc/luasrc/rpcc.luadoc index 8c90ab5247..5609bfd751 100644 --- a/libs/luci-lib-rpcc/luasrc/rpcc.luadoc +++ b/libs/luci-lib-rpcc/luasrc/rpcc.luadoc @@ -2,8 +2,8 @@ LuCI RPC Client. @cstyle instance -module "luci.rpcc" ]] +module "luci.rpcc" ---[[ Create a new JSON-RPC stream client. diff --git a/libs/luci-lib-rpcc/luasrc/rpcc/ruci.luadoc b/libs/luci-lib-rpcc/luasrc/rpcc/ruci.luadoc index 980ef46d97..9c842c5650 100644 --- a/libs/luci-lib-rpcc/luasrc/rpcc/ruci.luadoc +++ b/libs/luci-lib-rpcc/luasrc/rpcc/ruci.luadoc @@ -2,8 +2,8 @@ Transparent UCI over RPC client. @cstyle instance -module "luci.rpcc.ruci" ]] +module "luci.rpcc.ruci" ---[[ Create a new UCI over RPC proxy. |