mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-16 13:59:55 +02:00
complicated bug in ltn12.filter.chain...
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user