support for intermediate filters in ltn12.pump.all

This commit is contained in:
Fabien Fleutot 2013-06-18 11:21:47 +02:00
parent 480a818bf0
commit fbfd8ee680
2 changed files with 13 additions and 2 deletions

View file

@ -283,14 +283,17 @@ end
-----------------------------------------------------------------------------
-- pumps one chunk from the source to the sink
function pump.step(src, snk)
if ... then snk = ltn12.sink.chain(snk, ...) end
local chunk, src_err = src()
local ret, snk_err = snk(chunk, src_err)
if chunk and ret then return 1
else return nil, src_err or snk_err end
end
-- pumps all data from a source to a sink, using a step function
function pump.all(src, snk, step)
-- pumps all data from a source to a sink, optionally going through
-- intermediate filters
function pump.all(src, snk, ...)
if ... then snk = ltn12.sink.chain(snk, ...) end
base.assert(src and snk)
step = step or pump.step
while true do

View file

@ -229,6 +229,14 @@ assert(ltn12.pump.all(source, sink), "returned error")
assert(table.concat(t) == double(double(double(s))), "mismatch")
print("ok")
--------------------------------
io.write("testing pump.all (with intermediate filters): ")
local source = ltn12.source.string(s)
sink, t = ltn12.sink.table()
assert(ltn12.pump.all(source, double, double, sink), "returned error")
assert(table.concat(t) == double(double(s)), "mismatch")
print("ok")
--------------------------------
io.write("testing filter.chain (and sink.chain, with split, merge): ")
source = ltn12.source.string(s)