diff options
author | Diego Nehab <diego.nehab@gmail.com> | 2013-09-09 09:48:46 -0700 |
---|---|---|
committer | Diego Nehab <diego.nehab@gmail.com> | 2013-09-09 09:48:46 -0700 |
commit | c715993fb8b4d1e79c437ad499cdfd403fb57a64 (patch) | |
tree | cf708b2380204727ba8ab947a7dc2cf3d3fbd85b /src | |
parent | 6bdb00e24ca88f271774c2102f631e70f04b249d (diff) | |
parent | 480a818bf0ef6de32527ba14fc2bb27e754d0612 (diff) | |
download | luasocket-c715993fb8b4d1e79c437ad499cdfd403fb57a64.tar.gz luasocket-c715993fb8b4d1e79c437ad499cdfd403fb57a64.tar.bz2 luasocket-c715993fb8b4d1e79c437ad499cdfd403fb57a64.zip |
Merge pull request #65 from fab13n/480a818bf0ef6de32527ba14fc2bb27e754d0612
Support for several filters in ltn12.{sink,source}.chain
Diffstat (limited to 'src')
-rw-r--r-- | src/ltn12.lua | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ltn12.lua b/src/ltn12.lua index 5b10f56..1014de2 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua | |||
@@ -139,7 +139,9 @@ function source.rewind(src) | |||
139 | end | 139 | end |
140 | end | 140 | end |
141 | 141 | ||
142 | function source.chain(src, f) | 142 | -- chains a source with one or several filter(s) |
143 | function source.chain(src, f, ...) | ||
144 | if ... then f=filter.chain(f, ...) end | ||
143 | base.assert(src and f) | 145 | base.assert(src and f) |
144 | local last_in, last_out = "", "" | 146 | local last_in, last_out = "", "" |
145 | local state = "feeding" | 147 | local state = "feeding" |
@@ -254,8 +256,13 @@ function sink.error(err) | |||
254 | end | 256 | end |
255 | end | 257 | end |
256 | 258 | ||
257 | -- chains a sink with a filter | 259 | -- chains a sink with one or several filter(s) |
258 | function sink.chain(f, snk) | 260 | function sink.chain(f, snk, ...) |
261 | if ... then | ||
262 | local args = { f, snk, ... } | ||
263 | snk = table.remove(args, #args) | ||
264 | f = filter.chain(unpack(args)) | ||
265 | end | ||
259 | base.assert(f and snk) | 266 | base.assert(f and snk) |
260 | return function(chunk, err) | 267 | return function(chunk, err) |
261 | if chunk ~= "" then | 268 | if chunk ~= "" then |