aboutsummaryrefslogtreecommitdiff
path: root/src/ltn12.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2005-11-22 08:33:29 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2005-11-22 08:33:29 +0000
commitd55a5826e81136a9ecf65c4cd407152a56684dc2 (patch)
tree109ad44c75cee890ad5e98583e12b15b5e65a18e /src/ltn12.lua
parenta2b780bf7a78c66d54a248fa99b5fc862c12a127 (diff)
downloadluasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.gz
luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.bz2
luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.zip
Few tweaks in installation, some missing files, etc.
Diffstat (limited to 'src/ltn12.lua')
-rw-r--r--src/ltn12.lua30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/ltn12.lua b/src/ltn12.lua
index 2c16253..c49d130 100644
--- a/src/ltn12.lua
+++ b/src/ltn12.lua
@@ -36,19 +36,19 @@ end
36 36
37-- chains a bunch of filters together 37-- chains a bunch of filters together
38-- (thanks to Wim Couwenberg) 38-- (thanks to Wim Couwenberg)
39function filter.chain(...) 39function filter.chain(...)
40 local n = table.getn(arg) 40 local n = table.getn(arg)
41 local top, index = 1, 1 41 local top, index = 1, 1
42 local retry = "" 42 local retry = ""
43 return function(chunk) 43 return function(chunk)
44 retry = chunk and retry 44 retry = chunk and retry
45 while true do 45 while true do
46 if index == top then 46 if index == top then
47 chunk = arg[index](chunk) 47 chunk = arg[index](chunk)
48 if chunk == "" or top == n then return chunk 48 if chunk == "" or top == n then return chunk
49 elseif chunk then index = index + 1 49 elseif chunk then index = index + 1
50 else 50 else
51 top = top+1 51 top = top+1
52 index = top 52 index = top
53 end 53 end
54 else 54 else
@@ -148,9 +148,9 @@ function source.chain(src, f)
148 last_in, err = src() 148 last_in, err = src()
149 if err then return nil, err end 149 if err then return nil, err end
150 last_out = f(last_in) 150 last_out = f(last_in)
151 if not last_out then 151 if not last_out then
152 if last_in then 152 if last_in then
153 base.error('filter returned inappropriate nil') 153 base.error('filter returned inappropriate nil')
154 else 154 else
155 return nil 155 return nil
156 end 156 end
@@ -159,17 +159,17 @@ function source.chain(src, f)
159 if last_in then last_in = "" end 159 if last_in then last_in = "" end
160 return last_out 160 return last_out
161 end 161 end
162 else 162 else
163 last_out = f(last_in) 163 last_out = f(last_in)
164 if last_out == "" then 164 if last_out == "" then
165 if last_in == "" then 165 if last_in == "" then
166 state = "feeding" 166 state = "feeding"
167 else 167 else
168 base.error('filter returned ""') 168 base.error('filter returned ""')
169 end 169 end
170 elseif not last_out then 170 elseif not last_out then
171 if last_in then 171 if last_in then
172 base.error('filter returned inappropriate nil') 172 base.error('filter returned inappropriate nil')
173 else 173 else
174 return nil 174 return nil
175 end 175 end
@@ -224,7 +224,7 @@ end
224function sink.file(handle, io_err) 224function sink.file(handle, io_err)
225 if handle then 225 if handle then
226 return function(chunk, err) 226 return function(chunk, err)
227 if not chunk then 227 if not chunk then
228 handle:close() 228 handle:close()
229 return 1 229 return 1
230 else return handle:write(chunk) end 230 else return handle:write(chunk) end
@@ -248,7 +248,7 @@ function sink.error(err)
248 end 248 end
249end 249end
250 250
251-- chains a sink with a filter 251-- chains a sink with a filter
252function sink.chain(f, snk) 252function sink.chain(f, snk)
253 base.assert(f and snk) 253 base.assert(f and snk)
254 return function(chunk, err) 254 return function(chunk, err)
@@ -282,7 +282,7 @@ function pump.all(src, snk, step)
282 step = step or pump.step 282 step = step or pump.step
283 while true do 283 while true do
284 local ret, err = step(src, snk) 284 local ret, err = step(src, snk)
285 if not ret then 285 if not ret then
286 if err then return nil, err 286 if err then return nil, err
287 else return 1 end 287 else return 1 end
288 end 288 end