diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-11-27 07:58:04 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-11-27 07:58:04 +0000 |
commit | 7c97e8e40aaa665226fb54449773dc3134e755b2 (patch) | |
tree | 47888d4c924fc24bf3b355bf58120ea3cdc74bc4 /src/tp.lua | |
parent | eb0fc857ddea6f084d338589e2a33d3e7d4eade6 (diff) | |
download | luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.gz luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.bz2 luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.zip |
Almost ready for beta3
Diffstat (limited to 'src/tp.lua')
-rw-r--r-- | src/tp.lua | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -8,10 +8,12 @@ | |||
8 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
9 | -- Declare module and import dependencies | 9 | -- Declare module and import dependencies |
10 | ----------------------------------------------------------------------------- | 10 | ----------------------------------------------------------------------------- |
11 | local base = require("base") | ||
12 | local string = require("string") | ||
11 | local socket = require("socket") | 13 | local socket = require("socket") |
12 | local ltn12 = require("ltn12") | 14 | local ltn12 = require("ltn12") |
13 | 15 | ||
14 | module("socket.tp") | 16 | local tp = module("socket.tp") |
15 | 17 | ||
16 | ----------------------------------------------------------------------------- | 18 | ----------------------------------------------------------------------------- |
17 | -- Program constants | 19 | -- Program constants |
@@ -47,22 +49,27 @@ local metat = { __index = {} } | |||
47 | function metat.__index:check(ok) | 49 | function metat.__index:check(ok) |
48 | local code, reply = get_reply(self.c) | 50 | local code, reply = get_reply(self.c) |
49 | if not code then return nil, reply end | 51 | if not code then return nil, reply end |
50 | if type(ok) ~= "function" then | 52 | if base.type(ok) ~= "function" then |
51 | if type(ok) == "table" then | 53 | if base.type(ok) == "table" then |
52 | for i, v in ipairs(ok) do | 54 | for i, v in base.ipairs(ok) do |
53 | if string.find(code, v) then return tonumber(code), reply end | 55 | if string.find(code, v) then |
56 | return base.tonumber(code), reply | ||
57 | end | ||
54 | end | 58 | end |
55 | return nil, reply | 59 | return nil, reply |
56 | else | 60 | else |
57 | if string.find(code, ok) then return tonumber(code), reply | 61 | if string.find(code, ok) then return base.tonumber(code), reply |
58 | else return nil, reply end | 62 | else return nil, reply end |
59 | end | 63 | end |
60 | else return ok(tonumber(code), reply) end | 64 | else return ok(base.tonumber(code), reply) end |
61 | end | 65 | end |
62 | 66 | ||
63 | function metat.__index:command(cmd, arg) | 67 | function metat.__index:command(cmd, arg) |
64 | if arg then return self.c:send(cmd .. " " .. arg.. "\r\n") | 68 | if arg then |
65 | else return self.c:send(cmd .. "\r\n") end | 69 | return self.c:send(cmd .. " " .. arg.. "\r\n") |
70 | else | ||
71 | return self.c:send(cmd .. "\r\n") | ||
72 | end | ||
66 | end | 73 | end |
67 | 74 | ||
68 | function metat.__index:sink(snk, pat) | 75 | function metat.__index:sink(snk, pat) |
@@ -111,5 +118,7 @@ function connect(host, port, timeout) | |||
111 | c:close() | 118 | c:close() |
112 | return nil, e | 119 | return nil, e |
113 | end | 120 | end |
114 | return setmetatable({c = c}, metat) | 121 | return base.setmetatable({c = c}, metat) |
115 | end | 122 | end |
123 | |||
124 | base.setmetatable(tp, nil) | ||