complicated bug in ltn12.filter.chain...

This commit is contained in:
Diego Nehab 2004-04-01 07:32:53 +00:00
parent e5a090b01c
commit d92132e87a
3 changed files with 65 additions and 9 deletions

View file

@ -34,8 +34,23 @@ end
local function chain2(f1, f2)
if type(f1) ~= 'function' then error('invalid filter', 2) end
if type(f2) ~= 'function' then error('invalid filter', 2) end
local co = coroutine.create(function(chunk)
while true do
local filtered1 = f1(chunk)
local filtered2 = f2(filtered1)
local done2 = filtered1 and ""
while true do
if filtered2 == "" or filtered2 == nil then break end
coroutine.yield(filtered2)
filtered2 = f2(done2)
end
if filtered1 == "" then chunk = coroutine.yield(filtered1)
elseif filtered1 == nil then return nil
else chunk = chunk and "" end
end
end)
return function(chunk)
return f2(f1(chunk))
return shift(coroutine.resume(co, chunk))
end
end