aboutsummaryrefslogtreecommitdiff
path: root/src/ltn12.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-28 02:36:07 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-28 02:36:07 +0000
commit297b32e828b76ee544c9d4f89f996eda78830cc0 (patch)
tree312ca3a296b1e959acddeca9303cb238ac8324dc /src/ltn12.lua
parent05e8f243851049cebda6c5b690d3cde0f1e2c874 (diff)
downloadluasocket-297b32e828b76ee544c9d4f89f996eda78830cc0.tar.gz
luasocket-297b32e828b76ee544c9d4f89f996eda78830cc0.tar.bz2
luasocket-297b32e828b76ee544c9d4f89f996eda78830cc0.zip
LTN12 bug removed.
Diffstat (limited to 'src/ltn12.lua')
-rw-r--r--src/ltn12.lua26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/ltn12.lua b/src/ltn12.lua
index 5216ff6..1a13a43 100644
--- a/src/ltn12.lua
+++ b/src/ltn12.lua
@@ -40,30 +40,27 @@ end
40function filter.chain(...) 40function filter.chain(...)
41 local n = table.getn(arg) 41 local n = table.getn(arg)
42 local top, index = 1, 1 42 local top, index = 1, 1
43 local retry = ""
43 return function(chunk) 44 return function(chunk)
45 retry = chunk and retry
44 while true do 46 while true do
45 if index == top then 47 if index == top then
46 chunk = arg[index](chunk) 48 chunk = arg[index](chunk)
47 if chunk == "" or top == n then 49 if chunk == "" or top == n then return chunk
48 return chunk 50 elseif chunk then index = index + 1
49 elseif chunk then
50 index = index + 1
51 else 51 else
52 top = top+1 52 top = top+1
53 index = top 53 index = top
54 end 54 end
55 else 55 else
56 local original = chunk 56 chunk = arg[index](chunk or "")
57 chunk = arg[index](original or "")
58 if chunk == "" then 57 if chunk == "" then
59 index = index - 1 58 index = index - 1
60 chunk = original and chunk 59 chunk = retry
61 elseif chunk then 60 elseif chunk then
62 if index == n then return chunk 61 if index == n then return chunk
63 else index = index + 1 end 62 else index = index + 1 end
64 else 63 else base.error("filter returned inappropriate nil") end
65 base.error("filter returned inappropriate nil")
66 end
67 end 64 end
68 end 65 end
69 end 66 end
@@ -138,6 +135,8 @@ function source.rewind(src)
138 end 135 end
139end 136end
140 137
138local print = print
139
141-- chains a source with a filter 140-- chains a source with a filter
142function source.chain(src, f) 141function source.chain(src, f)
143 base.assert(src and f) 142 base.assert(src and f)
@@ -151,13 +150,16 @@ function source.chain(src, f)
151 last_out = f(last_in) 150 last_out = f(last_in)
152 if last_out ~= "" then return last_out end 151 if last_out ~= "" then return last_out end
153 if not last_in then 152 if not last_in then
154 error('filter returned inappropriate ""') 153 base.error('filter returned inappropriate ""')
155 end 154 end
156 end 155 end
157 elseif last_out then 156 elseif last_out then
158 last_out = f(last_in and "") 157 last_out = f(last_in and "")
159 if last_in and not last_out then 158 if last_in and not last_out then
160 error('filter returned inappropriate nil') 159 base.error('filter returned inappropriate nil')
160 end
161 if last_out == "" and not last_in then
162 base.error(base.tostring(f) .. ' returned inappropriate ""')
161 end 163 end
162 return last_out 164 return last_out
163 else 165 else