aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2013-09-09 09:48:46 -0700
committerDiego Nehab <diego.nehab@gmail.com>2013-09-09 09:48:46 -0700
commitc715993fb8b4d1e79c437ad499cdfd403fb57a64 (patch)
treecf708b2380204727ba8ab947a7dc2cf3d3fbd85b /src
parent6bdb00e24ca88f271774c2102f631e70f04b249d (diff)
parent480a818bf0ef6de32527ba14fc2bb27e754d0612 (diff)
downloadluasocket-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.lua13
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
140end 140end
141 141
142function source.chain(src, f) 142-- chains a source with one or several filter(s)
143function 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
255end 257end
256 258
257-- chains a sink with a filter 259-- chains a sink with one or several filter(s)
258function sink.chain(f, snk) 260function 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