diff options
-rw-r--r-- | etc/check-links.lua | 2 | ||||
-rw-r--r-- | etc/dispatch.lua | 7 | ||||
-rw-r--r-- | etc/forward.lua | 2 | ||||
-rw-r--r-- | etc/get.lua | 2 | ||||
-rw-r--r-- | ltn012.wiki | 6 | ||||
-rw-r--r-- | ltn013.wiki | 6 | ||||
-rw-r--r-- | luasocket-2.1-1.rockspec | 67 | ||||
-rw-r--r-- | samples/lpr.lua | 4 | ||||
-rw-r--r-- | samples/tinyirc.lua | 2 | ||||
-rw-r--r-- | src/mbox.lua | 4 | ||||
-rw-r--r-- | src/url.lua | 4 | ||||
-rw-r--r-- | test/httptest.lua | 2 | ||||
-rw-r--r-- | test/smtptest.lua | 14 | ||||
-rw-r--r-- | test/urltest.lua | 2 | ||||
-rw-r--r-- | test/utestclnt.lua | 8 |
15 files changed, 100 insertions, 32 deletions
diff --git a/etc/check-links.lua b/etc/check-links.lua index d2e4266..283f3ac 100644 --- a/etc/check-links.lua +++ b/etc/check-links.lua | |||
@@ -11,7 +11,7 @@ dispatch.TIMEOUT = 10 | |||
11 | 11 | ||
12 | -- make sure the user knows how to invoke us | 12 | -- make sure the user knows how to invoke us |
13 | arg = arg or {} | 13 | arg = arg or {} |
14 | if table.getn(arg) < 1 then | 14 | if #arg < 1 then |
15 | print("Usage:\n luasocket check-links.lua [-n] {<url>}") | 15 | print("Usage:\n luasocket check-links.lua [-n] {<url>}") |
16 | exit() | 16 | exit() |
17 | end | 17 | end |
diff --git a/etc/dispatch.lua b/etc/dispatch.lua index cc8cb23..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 |
@@ -76,7 +76,7 @@ local function newset() | |||
76 | insert = function(set, value) | 76 | insert = function(set, value) |
77 | if not reverse[value] then | 77 | if not reverse[value] then |
78 | table.insert(set, value) | 78 | table.insert(set, value) |
79 | reverse[value] = table.getn(set) | 79 | reverse[value] = #set |
80 | end | 80 | end |
81 | end, | 81 | end, |
82 | remove = function(set, value) | 82 | remove = function(set, value) |
@@ -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/etc/forward.lua b/etc/forward.lua index 9073ac4..05ced1a 100644 --- a/etc/forward.lua +++ b/etc/forward.lua | |||
@@ -3,7 +3,7 @@ local dispatch = require("dispatch") | |||
3 | local handler = dispatch.newhandler() | 3 | local handler = dispatch.newhandler() |
4 | 4 | ||
5 | -- make sure the user knows how to invoke us | 5 | -- make sure the user knows how to invoke us |
6 | if table.getn(arg) < 1 then | 6 | if #arg < 1 then |
7 | print("Usage") | 7 | print("Usage") |
8 | print(" lua forward.lua <iport:ohost:oport> ...") | 8 | print(" lua forward.lua <iport:ohost:oport> ...") |
9 | os.exit(1) | 9 | os.exit(1) |
diff --git a/etc/get.lua b/etc/get.lua index 4196f00..9edc235 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
@@ -135,7 +135,7 @@ end | |||
135 | 135 | ||
136 | -- main program | 136 | -- main program |
137 | arg = arg or {} | 137 | arg = arg or {} |
138 | if table.getn(arg) < 1 then | 138 | if #arg < 1 then |
139 | io.write("Usage:\n lua get.lua <remote-url> [<local-file>]\n") | 139 | io.write("Usage:\n lua get.lua <remote-url> [<local-file>]\n") |
140 | os.exit(1) | 140 | os.exit(1) |
141 | else get(arg[1], arg[2]) end | 141 | else get(arg[1], arg[2]) 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) | |||
126 | end | 126 | end |
127 | 127 | ||
128 | function filter.chain(...) | 128 | function 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 | |||
235 | We 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 | We 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 | {{{ |
237 | function source.cat(...) | 238 | function 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 | |||
73 | We 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: | 73 | We 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 | {{{ |
75 | local function pack(ok, ...) | 75 | local function pack(ok, ...) |
76 | return ok, arg | 76 | return ok, {...} |
77 | end | 77 | end |
78 | 78 | ||
79 | function protect(f) | 79 | function 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 |
163 | end | 163 | end |
diff --git a/luasocket-2.1-1.rockspec b/luasocket-2.1-1.rockspec new file mode 100644 index 0000000..9c59abe --- /dev/null +++ b/luasocket-2.1-1.rockspec | |||
@@ -0,0 +1,67 @@ | |||
1 | package = "LuaSocket" | ||
2 | version = "2.1-1" | ||
3 | source = { | ||
4 | url = "git://github.com/diegonehab/luasocket.git", | ||
5 | branch = "unstable" | ||
6 | } | ||
7 | description = { | ||
8 | summary = "Network support for the Lua language", | ||
9 | detailed = [[ | ||
10 | LuaSocket is a Lua extension library that is composed by two parts: a C core | ||
11 | that provides support for the TCP and UDP transport layers, and a set of Lua | ||
12 | modules that add support for functionality commonly needed by applications | ||
13 | that deal with the Internet. | ||
14 | ]], | ||
15 | homepage = "http://luaforge.net/projects/luasocket/", | ||
16 | license = "MIT" | ||
17 | } | ||
18 | dependencies = { | ||
19 | "lua >= 5.1" | ||
20 | } | ||
21 | build = { | ||
22 | type = "make", | ||
23 | build_variables = { | ||
24 | PLAT="linux", | ||
25 | LUAINC_linux="$(LUA_INCDIR)" | ||
26 | }, | ||
27 | install_variables = { | ||
28 | INSTALL_TOP_SHARE = "$(LUADIR)", | ||
29 | INSTALL_TOP_LIB = "$(LIBDIR)" | ||
30 | }, | ||
31 | platforms = { | ||
32 | macosx = { | ||
33 | build_variables = { | ||
34 | PLAT="macosx", | ||
35 | LUAINC_macosx="$(LUA_INCDIR)" | ||
36 | } | ||
37 | }, | ||
38 | windows={ | ||
39 | type= "command", | ||
40 | build_command= | ||
41 | "set INCLUDE=$(LUA_INCDIR);%INCLUDE% &".. | ||
42 | "set LIB=$(LUA_LIBDIR);%LIB% &".. | ||
43 | "msbuild /p:\"VCBuildAdditionalOptions= /useenv\" luasocket.sln &".. | ||
44 | "mkdir mime & mkdir socket &".. | ||
45 | "cp src/mime.dll mime/core.dll &".. | ||
46 | "cp src/socket.dll socket/core.dll", | ||
47 | install= { | ||
48 | lib = { | ||
49 | ["mime.core"] = "mime/core.dll", | ||
50 | ["socket.core"] = "socket/core.dll" | ||
51 | }, | ||
52 | lua = { | ||
53 | "src/ltn12.lua", | ||
54 | "src/mime.lua", | ||
55 | "src/socket.lua", | ||
56 | ["socket.headers"] = "src/headers.lua", | ||
57 | ["socket.ftp"] = "src/ftp.lua", | ||
58 | ["socket.http"] = "src/http.lua", | ||
59 | ["socket.smtp"] = "src/smtp.lua", | ||
60 | ["socket.tp"] = "src/tp.lua", | ||
61 | ["socket.url"] = "src/url.lua", | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | }, | ||
66 | copy_directories = { "doc", "samples", "etc", "test" } | ||
67 | } | ||
diff --git a/samples/lpr.lua b/samples/lpr.lua index 2b059b1..49a1dfa 100644 --- a/samples/lpr.lua +++ b/samples/lpr.lua | |||
@@ -28,8 +28,8 @@ end | |||
28 | 28 | ||
29 | do | 29 | do |
30 | local opt = {} | 30 | local opt = {} |
31 | local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)" | 31 | local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]?.?)" |
32 | for i = 2, table.getn(arg), 1 do | 32 | for i = 2, #arg, 1 do |
33 | string.gsub(arg[i], pat, function(name, value) opt[name] = value end) | 33 | string.gsub(arg[i], pat, function(name, value) opt[name] = value end) |
34 | end | 34 | end |
35 | if not arg[2] then | 35 | if not arg[2] then |
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index e75851f..5babb7e 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua | |||
@@ -31,7 +31,7 @@ function newset() | |||
31 | insert = function(set, value) | 31 | insert = function(set, value) |
32 | if not reverse[value] then | 32 | if not reverse[value] then |
33 | table.insert(set, value) | 33 | table.insert(set, value) |
34 | reverse[value] = table.getn(set) | 34 | reverse[value] = #set |
35 | end | 35 | end |
36 | end, | 36 | end, |
37 | remove = function(set, value) | 37 | remove = function(set, value) |
diff --git a/src/mbox.lua b/src/mbox.lua index b7d4a2a..35adf4e 100644 --- a/src/mbox.lua +++ b/src/mbox.lua | |||
@@ -34,7 +34,7 @@ end | |||
34 | function Public.parse_headers(headers_s) | 34 | function Public.parse_headers(headers_s) |
35 | local headers_t = Public.split_headers(headers_s) | 35 | local headers_t = Public.split_headers(headers_s) |
36 | local headers = {} | 36 | local headers = {} |
37 | for i = 1, table.getn(headers_t) do | 37 | for i = 1, #headers_t do |
38 | local name, value = Public.parse_header(headers_t[i]) | 38 | local name, value = Public.parse_header(headers_t[i]) |
39 | if name then | 39 | if name then |
40 | name = string.lower(name) | 40 | name = string.lower(name) |
@@ -74,7 +74,7 @@ end | |||
74 | 74 | ||
75 | function Public.parse(mbox_s) | 75 | function Public.parse(mbox_s) |
76 | local mbox = Public.split_mbox(mbox_s) | 76 | local mbox = Public.split_mbox(mbox_s) |
77 | for i = 1, table.getn(mbox) do | 77 | for i = 1, #mbox do |
78 | mbox[i] = Public.parse_message(mbox[i]) | 78 | mbox[i] = Public.parse_message(mbox[i]) |
79 | end | 79 | end |
80 | return mbox | 80 | return mbox |
diff --git a/src/url.lua b/src/url.lua index 1bfecad..6ca6d68 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -259,7 +259,7 @@ function parse_path(path) | |||
259 | path = path or "" | 259 | path = path or "" |
260 | --path = string.gsub(path, "%s", "") | 260 | --path = string.gsub(path, "%s", "") |
261 | string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end) | 261 | string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end) |
262 | for i = 1, table.getn(parsed) do | 262 | for i = 1, #parsed do |
263 | parsed[i] = unescape(parsed[i]) | 263 | parsed[i] = unescape(parsed[i]) |
264 | end | 264 | end |
265 | if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end | 265 | if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end |
@@ -277,7 +277,7 @@ end | |||
277 | ----------------------------------------------------------------------------- | 277 | ----------------------------------------------------------------------------- |
278 | function build_path(parsed, unsafe) | 278 | function build_path(parsed, unsafe) |
279 | local path = "" | 279 | local path = "" |
280 | local n = table.getn(parsed) | 280 | local n = #parsed |
281 | if unsafe then | 281 | if unsafe then |
282 | for i = 1, n-1 do | 282 | for i = 1, n-1 do |
283 | path = path .. parsed[i] | 283 | path = path .. parsed[i] |
diff --git a/test/httptest.lua b/test/httptest.lua index 614acf3..d5fbb37 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -66,7 +66,7 @@ local check_request = function(request, expect, ignore) | |||
66 | local response = {} | 66 | local response = {} |
67 | response.code, response.headers, response.status = | 67 | response.code, response.headers, response.status = |
68 | socket.skip(1, http.request(request)) | 68 | socket.skip(1, http.request(request)) |
69 | if t and table.getn(t) > 0 then response.body = table.concat(t) end | 69 | if t and #t > 0 then response.body = table.concat(t) end |
70 | check_result(response, expect, ignore) | 70 | check_result(response, expect, ignore) |
71 | end | 71 | end |
72 | 72 | ||
diff --git a/test/smtptest.lua b/test/smtptest.lua index 5f0e0e5..b5380ff 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
@@ -20,7 +20,7 @@ dofile("testsupport.lua") | |||
20 | 20 | ||
21 | local total = function() | 21 | local total = function() |
22 | local t = 0 | 22 | local t = 0 |
23 | for i = 1, table.getn(sent) do | 23 | for i = 1, #sent do |
24 | t = t + sent[i].count | 24 | t = t + sent[i].count |
25 | end | 25 | end |
26 | return t | 26 | return t |
@@ -83,7 +83,7 @@ end | |||
83 | 83 | ||
84 | local check = function(sent, m) | 84 | local check = function(sent, m) |
85 | io.write("checking ", m.headers.title, ": ") | 85 | io.write("checking ", m.headers.title, ": ") |
86 | for i = 1, table.getn(sent) do | 86 | for i = 1, #sent do |
87 | local s = sent[i] | 87 | local s = sent[i] |
88 | if s.title == m.headers.title and s.count > 0 then | 88 | if s.title == m.headers.title and s.count > 0 then |
89 | check_headers(s.headers, m.headers) | 89 | check_headers(s.headers, m.headers) |
@@ -98,7 +98,7 @@ end | |||
98 | 98 | ||
99 | local insert = function(sent, message) | 99 | local insert = function(sent, message) |
100 | if type(message.rcpt) == "table" then | 100 | if type(message.rcpt) == "table" then |
101 | message.count = table.getn(message.rcpt) | 101 | message.count = #message.rcpt |
102 | else message.count = 1 end | 102 | else message.count = 1 end |
103 | message.headers = message.headers or {} | 103 | message.headers = message.headers or {} |
104 | message.headers.title = message.title | 104 | message.headers.title = message.title |
@@ -115,7 +115,7 @@ local wait = function(sentinel, n) | |||
115 | io.write("waiting for ", n, " messages: ") | 115 | io.write("waiting for ", n, " messages: ") |
116 | while 1 do | 116 | while 1 do |
117 | local mbox = parse(get()) | 117 | local mbox = parse(get()) |
118 | if n == table.getn(mbox) then break end | 118 | if n == #mbox then break end |
119 | if socket.time() - sentinel.time > 50 then | 119 | if socket.time() - sentinel.time > 50 then |
120 | to = 1 | 120 | to = 1 |
121 | break | 121 | break |
@@ -237,7 +237,7 @@ empty() | |||
237 | print("ok") | 237 | print("ok") |
238 | 238 | ||
239 | io.write("sending messages: ") | 239 | io.write("sending messages: ") |
240 | for i = 1, table.getn(sent) do | 240 | for i = 1, #sent do |
241 | ret, err = socket.smtp.mail(sent[i]) | 241 | ret, err = socket.smtp.mail(sent[i]) |
242 | if not ret then fail(err) end | 242 | if not ret then fail(err) end |
243 | io.write("+") | 243 | io.write("+") |
@@ -249,9 +249,9 @@ wait(mark(), total()) | |||
249 | 249 | ||
250 | io.write("parsing mailbox: ") | 250 | io.write("parsing mailbox: ") |
251 | local mbox = parse(get()) | 251 | local mbox = parse(get()) |
252 | print(table.getn(mbox) .. " messages found!") | 252 | print(#mbox .. " messages found!") |
253 | 253 | ||
254 | for i = 1, table.getn(mbox) do | 254 | for i = 1, #mbox do |
255 | check(sent, mbox[i]) | 255 | check(sent, mbox[i]) |
256 | end | 256 | end |
257 | 257 | ||
diff --git a/test/urltest.lua b/test/urltest.lua index 71e4428..32cb348 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
@@ -34,7 +34,7 @@ end | |||
34 | 34 | ||
35 | local check_parse_path = function(path, expect) | 35 | local check_parse_path = function(path, expect) |
36 | local parsed = socket.url.parse_path(path) | 36 | local parsed = socket.url.parse_path(path) |
37 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do | 37 | for i = 1, math.max(#parsed, #expect) do |
38 | if parsed[i] ~= expect[i] then | 38 | if parsed[i] ~= expect[i] then |
39 | print(path) | 39 | print(path) |
40 | os.exit() | 40 | os.exit() |
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" | |||
4 | host = "luasocket" | 4 | host = "luasocket" |
5 | 5 | ||
6 | function pass(...) | 6 | function 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") |
9 | end | 9 | end |
10 | 10 | ||
11 | function fail(...) | 11 | function 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") |
14 | socket.sleep(3) | 14 | socket.sleep(3) |
15 | os.exit() | 15 | os.exit() |
16 | end | 16 | end |
17 | 17 | ||
18 | function warn(...) | 18 | function 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") |
21 | end | 21 | end |
22 | 22 | ||
23 | function remote(...) | 23 | function 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*", "") |