Merge pull request #65 from fab13n/480a818bf0ef6de32527ba14fc2bb27e754d0612

Support for several filters in ltn12.{sink,source}.chain
This commit is contained in:
Diego Nehab
2013-09-09 09:48:46 -07:00
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