aboutsummaryrefslogtreecommitdiff
path: root/src/ltn12.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-04-01 07:32:53 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-04-01 07:32:53 +0000
commitd92132e87a48368db849f8ba8f30ff8ce5de6156 (patch)
treee88deb991cbe2592b6ba5a1519519384c64ff85c /src/ltn12.lua
parente5a090b01cd5b490f7331235b7c58c36c05bb7b6 (diff)
downloadluasocket-d92132e87a48368db849f8ba8f30ff8ce5de6156.tar.gz
luasocket-d92132e87a48368db849f8ba8f30ff8ce5de6156.tar.bz2
luasocket-d92132e87a48368db849f8ba8f30ff8ce5de6156.zip
complicated bug in ltn12.filter.chain...
Diffstat (limited to 'src/ltn12.lua')
-rw-r--r--src/ltn12.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/ltn12.lua b/src/ltn12.lua
index ed3449b..dac932b 100644
--- a/src/ltn12.lua
+++ b/src/ltn12.lua
@@ -34,8 +34,23 @@ end
34local function chain2(f1, f2) 34local function chain2(f1, f2)
35 if type(f1) ~= 'function' then error('invalid filter', 2) end 35 if type(f1) ~= 'function' then error('invalid filter', 2) end
36 if type(f2) ~= 'function' then error('invalid filter', 2) end 36 if type(f2) ~= 'function' then error('invalid filter', 2) end
37 local co = coroutine.create(function(chunk)
38 while true do
39 local filtered1 = f1(chunk)
40 local filtered2 = f2(filtered1)
41 local done2 = filtered1 and ""
42 while true do
43 if filtered2 == "" or filtered2 == nil then break end
44 coroutine.yield(filtered2)
45 filtered2 = f2(done2)
46 end
47 if filtered1 == "" then chunk = coroutine.yield(filtered1)
48 elseif filtered1 == nil then return nil
49 else chunk = chunk and "" end
50 end
51 end)
37 return function(chunk) 52 return function(chunk)
38 return f2(f1(chunk)) 53 return shift(coroutine.resume(co, chunk))
39 end 54 end
40end 55end
41 56