diff options
author | Jan-Philipp Litza <janphilipp@litza.de> | 2015-09-01 16:17:23 +0200 |
---|---|---|
committer | Jan-Philipp Litza <janphilipp@litza.de> | 2015-09-04 12:21:30 +0200 |
commit | 5335f225374c7ed993348d15b5018411dc776bab (patch) | |
tree | 1a09ce68eac08178a96c162bb1f75528c398bb54 /libs/luci-lib-jsonc/src/jsonc.luadoc | |
parent | f0083abed10e8a397ebe9e62801e3b5d536ba7b6 (diff) |
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>
Diffstat (limited to 'libs/luci-lib-jsonc/src/jsonc.luadoc')
-rw-r--r-- | libs/luci-lib-jsonc/src/jsonc.luadoc | 14 |
1 files changed, 13 insertions, 1 deletions
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. |