support multiple filters in ltn12.{sink,source}.chain()

This commit is contained in:
Fabien Fleutot 2013-06-18 11:01:46 +02:00
parent 22cd5833fc
commit 480a818bf0
2 changed files with 35 additions and 3 deletions

View file

@ -139,7 +139,9 @@ function source.rewind(src)
end
end
function source.chain(src, f)
-- chains a source with one or several filter(s)
function source.chain(src, f, ...)
if ... then f=filter.chain(f, ...) end
base.assert(src and f)
local last_in, last_out = "", ""
local state = "feeding"
@ -254,8 +256,13 @@ function sink.error(err)
end
end
-- chains a sink with a filter
function sink.chain(f, snk)
-- chains a sink with one or several filter(s)
function sink.chain(f, snk, ...)
if ... then
local args = { f, snk, ... }
snk = table.remove(args, #args)
f = filter.chain(unpack(args))
end
base.assert(f and snk)
return function(chunk, err)
if chunk ~= "" then