Skip to content
Snippets Groups Projects
Select Git revision
  • d84028301eb7d2ebda43f0b0500116b9cad6ce6d
  • v2018.2.x default protected
  • 0x4A6F-rpi4
  • 0x4A6F-master
  • master
  • v2018.2.2-ffs
  • v2016.2.4-batmanbug
  • radv-filterd
  • v2016.2.x
  • hoodselector
  • v2016.1.x
  • babel
  • v2015.1.x
  • 2014.4.x
  • 2014.3.x
  • v2018.2.2-ffs0.1
  • v2018.2.1-ffs0.1
  • v2018.2.1
  • v2018.2-ffs0.1
  • v2018.2
  • v2018.1.4
  • v2018.1.3
  • v2018.1.2
  • v2018.1.1
  • v2018.1
  • v2017.1.8
  • v2017.1.7
  • v2017.1.6
  • v2017.1.5
  • v2017.1.4
  • v2017.1.3
  • v2017.1.2
  • v2016.2.7
  • v2017.1.1
  • v2017.1
35 results

0006-luci-lib-jsonc-Add-ltn12-compatible-sink-factory.patch

Blame
  • Forked from firmware / FFS Gluon
    Source project has a limited visibility.
    0006-luci-lib-jsonc-Add-ltn12-compatible-sink-factory.patch 3.38 KiB
    From: Jan-Philipp Litza <janphilipp@litza.de>
    Date: Tue, 1 Sep 2015 16:17:23 +0200
    Subject: luci-lib-jsonc: Add ltn12-compatible sink factory
    
    To use the luci-lib-jsonc parser as sink for an ltn12 pump (for example
    from stdin), the following code will now do:
    
        require 'luci.ltn12'
        require 'luci.jsonc'
    
        local parser = luci.jsonc.new()
        luci.ltn12.pump.all(luci.ltn12.source.file(io.input()), parser:sink())
        print(parser:get())
    
    Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
    
    diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c
    index b857c97..ef11101 100644
    --- a/libs/luci-lib-jsonc/src/jsonc.c
    +++ b/libs/luci-lib-jsonc/src/jsonc.c
    @@ -328,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);