diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-04-01 07:32:53 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-04-01 07:32:53 +0000 |
| commit | d92132e87a48368db849f8ba8f30ff8ce5de6156 (patch) | |
| tree | e88deb991cbe2592b6ba5a1519519384c64ff85c /src | |
| parent | e5a090b01cd5b490f7331235b7c58c36c05bb7b6 (diff) | |
| download | luasocket-d92132e87a48368db849f8ba8f30ff8ce5de6156.tar.gz luasocket-d92132e87a48368db849f8ba8f30ff8ce5de6156.tar.bz2 luasocket-d92132e87a48368db849f8ba8f30ff8ce5de6156.zip | |
complicated bug in ltn12.filter.chain...
Diffstat (limited to 'src')
| -rw-r--r-- | src/ltn12.lua | 17 |
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 | |||
| 34 | local function chain2(f1, f2) | 34 | local 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 |
| 40 | end | 55 | end |
| 41 | 56 | ||
