aboutsummaryrefslogtreecommitdiff
path: root/src/ltn12.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-03-19 05:04:03 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-03-19 05:04:03 +0000
commite896454e6c7fb574f405729e1ce94c223578e078 (patch)
treeb9cbcb092ee8bc16fe21a9f6ae6bf07ed052fd50 /src/ltn12.lua
parent2c160627e51650f98d6ef01ae36bb86d6e91045f (diff)
downloadluasocket-e896454e6c7fb574f405729e1ce94c223578e078.tar.gz
luasocket-e896454e6c7fb574f405729e1ce94c223578e078.tar.bz2
luasocket-e896454e6c7fb574f405729e1ce94c223578e078.zip
Seems to be working.
Diffstat (limited to 'src/ltn12.lua')
-rw-r--r--src/ltn12.lua10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/ltn12.lua b/src/ltn12.lua
index f43e975..ef6247d 100644
--- a/src/ltn12.lua
+++ b/src/ltn12.lua
@@ -16,7 +16,7 @@ local function second(a, b)
16 return b 16 return b
17end 17end
18 18
19local function skip(a, b, c) 19local function shift(a, b, c)
20 return b, c 20 return b, c
21end 21end
22 22
@@ -69,7 +69,7 @@ function source.file(handle, io_err)
69 if not chunk then handle:close() end 69 if not chunk then handle:close() end
70 return chunk 70 return chunk
71 end 71 end
72 else source.error(io_err or "unable to open file") end 72 else return source.error(io_err or "unable to open file") end
73end 73end
74 74
75-- turns a fancy source into a simple source 75-- turns a fancy source into a simple source
@@ -114,6 +114,7 @@ function source.chain(src, f)
114 local co = coroutine.create(function() 114 local co = coroutine.create(function()
115 while true do 115 while true do
116 local chunk, err = src() 116 local chunk, err = src()
117 if err then return nil, err end
117 local filtered = f(chunk) 118 local filtered = f(chunk)
118 local done = chunk and "" 119 local done = chunk and ""
119 while true do 120 while true do
@@ -121,11 +122,10 @@ function source.chain(src, f)
121 if filtered == done then break end 122 if filtered == done then break end
122 filtered = f(done) 123 filtered = f(done)
123 end 124 end
124 if not chunk then return nil, err end
125 end 125 end
126 end) 126 end)
127 return function() 127 return function()
128 return skip(coroutine.resume(co)) 128 return shift(coroutine.resume(co))
129 end 129 end
130end 130end
131 131
@@ -141,7 +141,7 @@ function source.cat(...)
141 end 141 end
142 end) 142 end)
143 return source.simplify(function() 143 return source.simplify(function()
144 return second(coroutine.resume(co)) 144 return shift(coroutine.resume(co))
145 end) 145 end)
146end 146end
147 147