From 534b0cedf714d4de0a6cf67570e11f232cdccf84 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sun, 28 Nov 2004 08:17:16 +0000 Subject: Added new instalation section to the manual. --- src/socket.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/socket.lua b/src/socket.lua index b3a4269..c3bbba9 100644 --- a/src/socket.lua +++ b/src/socket.lua @@ -7,8 +7,11 @@ ----------------------------------------------------------------------------- -- Declare module and import dependencies ----------------------------------------------------------------------------- -module("socket") +local base = require("base") +local string = require("string") +local math = require("math") local socket = require("lsocket") +module("socket") ----------------------------------------------------------------------------- -- Auxiliar functions @@ -40,11 +43,11 @@ socket.try = socket.newtry() function socket.choose(table) return function(name, opt1, opt2) - if type(name) ~= "string" then + if base.type(name) ~= "string" then name, opt1, opt2 = "default", name, opt1 end local f = table[name or "nil"] - if not f then error("unknown key (" .. tostring(name) .. ")", 3) + if not f then base.error("unknown key (".. base.tostring(name) ..")", 3) else return f(opt1, opt2) end end end @@ -59,7 +62,7 @@ socket.sinkt = {} socket.BLOCKSIZE = 2048 socket.sinkt["http-chunked"] = function(sock) - return setmetatable({ + return base.setmetatable({ getfd = function() return sock:getfd() end, dirty = function() return sock:dirty() end }, { @@ -72,7 +75,7 @@ socket.sinkt["http-chunked"] = function(sock) end socket.sinkt["close-when-done"] = function(sock) - return setmetatable({ + return base.setmetatable({ getfd = function() return sock:getfd() end, dirty = function() return sock:dirty() end }, { @@ -86,7 +89,7 @@ socket.sinkt["close-when-done"] = function(sock) end socket.sinkt["keep-open"] = function(sock) - return setmetatable({ + return base.setmetatable({ getfd = function() return sock:getfd() end, dirty = function() return sock:dirty() end }, { @@ -102,7 +105,7 @@ socket.sinkt["default"] = socket.sinkt["keep-open"] socket.sink = socket.choose(socket.sinkt) socket.sourcet["by-length"] = function(sock, length) - return setmetatable({ + return base.setmetatable({ getfd = function() return sock:getfd() end, dirty = function() return sock:dirty() end }, { @@ -119,7 +122,7 @@ end socket.sourcet["until-closed"] = function(sock) local done - return setmetatable({ + return base.setmetatable({ getfd = function() return sock:getfd() end, dirty = function() return sock:dirty() end }, { @@ -137,7 +140,7 @@ socket.sourcet["until-closed"] = function(sock) end socket.sourcet["http-chunked"] = function(sock) - return setmetatable({ + return base.setmetatable({ getfd = function() return sock:getfd() end, dirty = function() return sock:dirty() end }, { @@ -145,7 +148,7 @@ socket.sourcet["http-chunked"] = function(sock) -- get chunk size, skip extention local line, err = sock:receive() if err then return nil, err end - local size = tonumber(string.gsub(line, ";.*", ""), 16) + local size = base.tonumber(string.gsub(line, ";.*", ""), 16) if not size then return nil, "invalid chunk size" end -- was it the last chunk? if size <= 0 then @@ -168,3 +171,5 @@ end socket.sourcet["default"] = socket.sourcet["until-closed"] socket.source = socket.choose(socket.sourcet) + +base.setmetatable(socket, nil) -- cgit v1.2.3-55-g6feb