aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2013-04-17 19:38:21 -0700
committerDiego Nehab <diego.nehab@gmail.com>2013-04-17 19:38:21 -0700
commitc28fa1d3093e40e3cde365641755544003c83877 (patch)
tree731268dfb640681372bd66ce2f5d44cbeacda41c
parent00435529bb9a3a6614e9934fe20c27ada3dc2283 (diff)
parent33b4f0cfc7f0a0ebd5d4aaf9bbfe88a02d4368e7 (diff)
downloadluasocket-c28fa1d3093e40e3cde365641755544003c83877.tar.gz
luasocket-c28fa1d3093e40e3cde365641755544003c83877.tar.bz2
luasocket-c28fa1d3093e40e3cde365641755544003c83877.zip
Merge pull request #27 from catwell/pull-noarg
fix more uses of arg
Diffstat (limited to '')
-rw-r--r--etc/dispatch.lua5
-rw-r--r--ltn012.wiki6
-rw-r--r--ltn013.wiki6
-rw-r--r--test/utestclnt.lua8
4 files changed, 13 insertions, 12 deletions
diff --git a/etc/dispatch.lua b/etc/dispatch.lua
index 31a1290..cab7f59 100644
--- a/etc/dispatch.lua
+++ b/etc/dispatch.lua
@@ -50,7 +50,7 @@ function socket.protect(f)
50 return function(...) 50 return function(...)
51 local co = coroutine.create(f) 51 local co = coroutine.create(f)
52 while true do 52 while true do
53 local results = {coroutine.resume(co, base.unpack(arg))} 53 local results = {coroutine.resume(co, ...)}
54 local status = table.remove(results, 1) 54 local status = table.remove(results, 1)
55 if not status then 55 if not status then
56 if base.type(results[1]) == 'table' then 56 if base.type(results[1]) == 'table' then
@@ -104,8 +104,7 @@ local function cowrap(dispatcher, tcp, error)
104 -- don't override explicitly. 104 -- don't override explicitly.
105 local metat = { __index = function(table, key) 105 local metat = { __index = function(table, key)
106 table[key] = function(...) 106 table[key] = function(...)
107 arg[1] = tcp 107 return tcp[key](tcp,select(2,...))
108 return tcp[key](base.unpack(arg))
109 end 108 end
110 return table[key] 109 return table[key]
111 end} 110 end}
diff --git a/ltn012.wiki b/ltn012.wiki
index b924dd3..96b13ae 100644
--- a/ltn012.wiki
+++ b/ltn012.wiki
@@ -126,8 +126,9 @@ local function chain2(f1, f2)
126end 126end
127 127
128function filter.chain(...) 128function filter.chain(...)
129 local arg = {...}
129 local f = arg[1] 130 local f = arg[1]
130 for i = 2, table.getn(arg) do 131 for i = 2, #arg do
131 f = chain2(f, arg[i]) 132 f = chain2(f, arg[i])
132 end 133 end
133 return f 134 return f
@@ -235,9 +236,10 @@ end
235We can make these ideas even more powerful if we use a new feature of Lua 5.0: coroutines. Coroutines suffer from a great lack of advertisement, and I am going to play my part here. Just like lexical scoping, coroutines taste odd at first, but once you get used with the concept, it can save your day. I have to admit that using coroutines to implement our file source would be overkill, so let's implement a concatenated source factory instead. 236We can make these ideas even more powerful if we use a new feature of Lua 5.0: coroutines. Coroutines suffer from a great lack of advertisement, and I am going to play my part here. Just like lexical scoping, coroutines taste odd at first, but once you get used with the concept, it can save your day. I have to admit that using coroutines to implement our file source would be overkill, so let's implement a concatenated source factory instead.
236 {{{ 237 {{{
237function source.cat(...) 238function source.cat(...)
239 local arg = {...}
238 local co = coroutine.create(function() 240 local co = coroutine.create(function()
239 local i = 1 241 local i = 1
240 while i <= table.getn(arg) do 242 while i <= #arg do
241 local chunk, err = arg[i]() 243 local chunk, err = arg[i]()
242 if chunk then coroutine.yield(chunk) 244 if chunk then coroutine.yield(chunk)
243 elseif err then return nil, err 245 elseif err then return nil, err
diff --git a/ltn013.wiki b/ltn013.wiki
index 734b433..a622424 100644
--- a/ltn013.wiki
+++ b/ltn013.wiki
@@ -73,12 +73,12 @@ Fortunately, all these problems are very easy to solve and that's what we do in
73We used the {{pcall}} function to shield the user from errors that could be raised by the underlying implementation. Instead of directly using {{pcall}} (and thus duplicating code) every time we prefer a factory that does the same job: 73We used the {{pcall}} function to shield the user from errors that could be raised by the underlying implementation. Instead of directly using {{pcall}} (and thus duplicating code) every time we prefer a factory that does the same job:
74 {{{ 74 {{{
75local function pack(ok, ...) 75local function pack(ok, ...)
76 return ok, arg 76 return ok, {...}
77end 77end
78 78
79function protect(f) 79function protect(f)
80 return function(...) 80 return function(...)
81 local ok, ret = pack(pcall(f, unpack(arg))) 81 local ok, ret = pack(pcall(f, ...))
82 if ok then return unpack(ret) 82 if ok then return unpack(ret)
83 else return nil, ret[1] end 83 else return nil, ret[1] end
84 end 84 end
@@ -157,7 +157,7 @@ function newtry(f)
157 if f then f() end 157 if f then f() end
158 error(arg[2], 0) 158 error(arg[2], 0)
159 else 159 else
160 return unpack(arg) 160 return ...
161 end 161 end
162 end 162 end
163end 163end
diff --git a/test/utestclnt.lua b/test/utestclnt.lua
index eec6adc..01f55e5 100644
--- a/test/utestclnt.lua
+++ b/test/utestclnt.lua
@@ -4,24 +4,24 @@ local socket = require"socket.unix"
4host = "luasocket" 4host = "luasocket"
5 5
6function pass(...) 6function pass(...)
7 local s = string.format(unpack(arg)) 7 local s = string.format(...)
8 io.stderr:write(s, "\n") 8 io.stderr:write(s, "\n")
9end 9end
10 10
11function fail(...) 11function fail(...)
12 local s = string.format(unpack(arg)) 12 local s = string.format(...)
13 io.stderr:write("ERROR: ", s, "!\n") 13 io.stderr:write("ERROR: ", s, "!\n")
14socket.sleep(3) 14socket.sleep(3)
15 os.exit() 15 os.exit()
16end 16end
17 17
18function warn(...) 18function warn(...)
19 local s = string.format(unpack(arg)) 19 local s = string.format(...)
20 io.stderr:write("WARNING: ", s, "\n") 20 io.stderr:write("WARNING: ", s, "\n")
21end 21end
22 22
23function remote(...) 23function remote(...)
24 local s = string.format(unpack(arg)) 24 local s = string.format(...)
25 s = string.gsub(s, "\n", ";") 25 s = string.gsub(s, "\n", ";")
26 s = string.gsub(s, "%s+", " ") 26 s = string.gsub(s, "%s+", " ")
27 s = string.gsub(s, "^%s*", "") 27 s = string.gsub(s, "^%s*", "")