Permalink
Browse files

corrects an error when calculating the return count for load and run …

…buffer

removes the usage of the Lua function 'module'
removes the usage of the C function luaL_openlib
removes the requirement that Lua 5.2 is compiled with LUA_COMPAT_MODULE
  • Loading branch information...
aDevilInMe committed Jul 15, 2011
1 parent 84c955a commit 027bc51a9883ec5ec75002a1d39f1890ba8a34e7
Showing with 198 additions and 151 deletions.
  1. +5 −6 embed_luasocket.lua
  2. +4 −0 src/except.c
  3. +16 −15 src/ftp.lua
  4. +4 −2 src/headers.lua
  5. +18 −17 src/http.lua
  6. +4 −0 src/inet.c
  7. +12 −10 src/ltn12.lua
  8. +5 −0 src/luasocket.c
  9. +5 −0 src/mime.c
  10. +19 −17 src/mime.lua
  11. +4 −0 src/select.c
  12. +18 −17 src/smtp.lua
  13. +17 −16 src/socket.lua
  14. +27 −27 src/socket_scripts.c
  15. +4 −0 src/tcp.c
  16. +4 −0 src/timeout.c
  17. +6 −4 src/tp.lua
  18. +4 −0 src/udp.c
  19. +17 −15 src/url.lua
  20. +2 −2 test/hello.lua
  21. +3 −3 test/testsrvr.lua
View
@@ -24,7 +24,7 @@
end
end
- local write_embedded_scripts_ = function(out,scripts,strip_file_function)
+ local write_embedded_scripts = function(out,scripts,strip_file_function)
local w = function(...) out.write(out,...) end
local sizes ={}
local last_entry = #scripts
@@ -104,7 +104,7 @@ static int load_and_run_buffer(lua_State* L,int char_buff_index,size_t buff_size
if (res == LUA_OK)
{
lua_pcall(L, 0, LUA_MULTRET, 0);
- return top - lua_gettop(L);
+ return lua_gettop(L) - top;
}
else if(res == LUA_ERRSYNTAX)
lua_pushliteral(L,"LUA_ERRSYNTAX");
@@ -183,7 +183,7 @@ end
-local write_loader_functions__ = function(out,embedded_scripts)
+local write_loader_functions = function(out,embedded_scripts)
loader_constant_prefix(out)
@@ -249,10 +249,9 @@ int luaopen_luasocket(struct lua_State *L);
local out = io.open("src/socket_scripts.c", "w+b")
out:write "/* This file is generated, edits to it will not persist if regenerated */ \n\n"
local stripfile = lstrip_stripfile
- --lua_stripfile
- write_embedded_scripts_(out,embedded_scripts,stripfile)
- write_loader_functions__(out,embedded_scripts)
+ write_embedded_scripts(out,embedded_scripts,stripfile)
+ write_loader_functions(out,embedded_scripts)
out:close()
end
View
@@ -94,6 +94,10 @@ static int global_protect(lua_State *L) {
* Init module
\*-------------------------------------------------------------------------*/
int except_open(lua_State *L) {
+#if LUA_VERSION_NUM == 502
+ luaL_setfuncs(L,func,0);
+#else
luaL_openlib(L, NULL, func, 0);
+#endif
return 0;
}
View
@@ -16,50 +16,50 @@ local socket = require("socket")
local url = require("socket.url")
local tp = require("socket.tp")
local ltn12 = require("ltn12")
-module("socket.ftp")
+local M = {}
-----------------------------------------------------------------------------
-- Program constants
-----------------------------------------------------------------------------
-- timeout in seconds before the program gives up on a connection
-TIMEOUT = 60
+M.TIMEOUT = 60
-- default port for ftp service
-PORT = 21
+M.PORT = 21
-- this is the default anonymous password. used when no password is
-- provided in url. should be changed to your e-mail.
-USER = "ftp"
-PASSWORD = "anonymous@anonymous.org"
+M.USER = "ftp"
+M.PASSWORD = "anonymous@anonymous.org"
-----------------------------------------------------------------------------
-- Low level FTP API
-----------------------------------------------------------------------------
local metat = { __index = {} }
-function open(server, port, create)
- local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT, create))
+function M.open(server, port, create)
+ local tp = socket.try(tp.connect(server, port or M.PORT, M.TIMEOUT, create))
local f = base.setmetatable({ tp = tp }, metat)
-- make sure everything gets closed in an exception
f.try = socket.newtry(function() f:close() end)
return f
end
function metat.__index:portconnect()
- self.try(self.server:settimeout(TIMEOUT))
+ self.try(self.server:settimeout(M.TIMEOUT))
self.data = self.try(self.server:accept())
- self.try(self.data:settimeout(TIMEOUT))
+ self.try(self.data:settimeout(M.TIMEOUT))
end
function metat.__index:pasvconnect()
self.data = self.try(socket.tcp())
- self.try(self.data:settimeout(TIMEOUT))
+ self.try(self.data:settimeout(M.TIMEOUT))
self.try(self.data:connect(self.pasvt.ip, self.pasvt.port))
end
function metat.__index:login(user, password)
- self.try(self.tp:command("user", user or USER))
+ self.try(self.tp:command("user", user or M.USER))
local code, reply = self.try(self.tp:check{"2..", 331})
if code == 331 then
- self.try(self.tp:command("pass", password or PASSWORD))
+ self.try(self.tp:command("pass", password or M.PASSWORD))
self.try(self.tp:check("2.."))
end
return 1
@@ -88,7 +88,7 @@ function metat.__index:port(ip, port)
ip, port = self.try(self.tp:getcontrol():getsockname())
self.server = self.try(socket.bind(ip, 0))
ip, port = self.try(self.server:getsockname())
- self.try(self.server:settimeout(TIMEOUT))
+ self.try(self.server:settimeout(M.TIMEOUT))
end
local pl = math.mod(port, 256)
local ph = (port - pl)/256
@@ -261,7 +261,7 @@ local function sget(u)
return table.concat(t)
end
-command = socket.protect(function(cmdt)
+M.command = socket.protect(function(cmdt)
cmdt = override(cmdt)
socket.try(cmdt.host, "missing hostname")
socket.try(cmdt.command, "missing command")
@@ -274,8 +274,9 @@ command = socket.protect(function(cmdt)
return f:close()
end)
-get = socket.protect(function(gett)
+M.get = socket.protect(function(gett)
if base.type(gett) == "string" then return sget(gett)
else return tget(gett) end
end)
+return M
View
@@ -4,9 +4,9 @@
-- Author: Diego Nehab
-- RCS ID: $Id$
-----------------------------------------------------------------------------
-module("socket.headers")
+local M ={}
-canonic = {
+M.canonic = {
["accept"] = "Accept",
["accept-charset"] = "Accept-Charset",
["accept-encoding"] = "Accept-Encoding",
@@ -98,3 +98,5 @@ canonic = {
["www-authenticate"] = "WWW-Authenticate",
["x-mailer"] = "X-Mailer",
}
+
+return M
View
@@ -16,17 +16,16 @@ local string = require("string")
local headers = require("socket.headers")
local base = _G
local table = require("table")
-module("socket.http")
-
+local M = {}
-----------------------------------------------------------------------------
-- Program constants
-----------------------------------------------------------------------------
-- connection timeout in seconds
-TIMEOUT = 60
+M.TIMEOUT = 60
-- default port for document retrieval
-PORT = 80
+M.PORT = 80
-- user agent field sent in request
-USERAGENT = socket._VERSION
+M.USERAGENT = socket._VERSION
-----------------------------------------------------------------------------
-- Reads MIME headers from a connection, unfolding where needed
@@ -106,15 +105,15 @@ end
-----------------------------------------------------------------------------
local metat = { __index = {} }
-function open(host, port, create)
+function M.open(host, port, create)
-- create socket with user connect function, or with default
local c = socket.try((create or socket.tcp)())
local h = base.setmetatable({ c = c }, metat)
-- create finalized try
h.try = socket.newtry(function() h:close() end)
-- set timeout before connecting
- h.try(c:settimeout(TIMEOUT))
- h.try(c:connect(host, port or PORT))
+ h.try(c:settimeout(M.TIMEOUT))
+ h.try(c:connect(host, port or M.PORT))
-- here everything worked
return h
end
@@ -186,7 +185,7 @@ end
local function adjusturi(reqt)
local u = reqt
-- if there is a proxy, we need the full url. otherwise, just a part.
- if not reqt.proxy and not PROXY then
+ if not reqt.proxy and not M.PROXY then
u = {
path = socket.try(reqt.path, "invalid path 'nil'"),
params = reqt.params,
@@ -198,7 +197,7 @@ local function adjusturi(reqt)
end
local function adjustproxy(reqt)
- local proxy = reqt.proxy or PROXY
+ local proxy = reqt.proxy or M.PROXY
if proxy then
proxy = url.parse(proxy)
return proxy.host, proxy.port or 3128
@@ -210,7 +209,7 @@ end
local function adjustheaders(reqt)
-- default headers
local lower = {
- ["user-agent"] = USERAGENT,
+ ["user-agent"] = M.USERAGENT,
["host"] = reqt.host,
["connection"] = "close, TE",
["te"] = "trailers"
@@ -230,7 +229,7 @@ end
-- default url parts
local default = {
host = "",
- port = PORT,
+ port = M.PORT,
path ="/",
scheme = "http"
}
@@ -271,7 +270,7 @@ end
-- forward declarations
local trequest, tredirect
-function tredirect(reqt, location)
+function M.tredirect(reqt, location)
local result, code, headers, status = trequest {
-- the RFC says the redirect URL has to be absolute, but some
-- servers do not respect that
@@ -289,7 +288,7 @@ function tredirect(reqt, location)
return result, code, headers, status
end
-function trequest(reqt)
+function M.trequest(reqt)
-- we loop until we get what we want, or
-- until we are sure there is no way to get it
local nreqt = adjustrequest(reqt)
@@ -342,11 +341,13 @@ local function srequest(u, b)
}
reqt.method = "POST"
end
- local code, headers, status = socket.skip(1, trequest(reqt))
+ local code, headers, status = socket.skip(1, M.trequest(reqt))
return table.concat(t), code, headers, status
end
-request = socket.protect(function(reqt, body)
+M.request = socket.protect(function(reqt, body)
if base.type(reqt) == "string" then return srequest(reqt, body)
- else return trequest(reqt) end
+ else return M.trequest(reqt) end
end)
+
+return M
View
@@ -40,7 +40,11 @@ int inet_open(lua_State *L)
{
lua_pushstring(L, "dns");
lua_newtable(L);
+#if LUA_VERSION_NUM == 502
+ luaL_setfuncs(L,func,0);
+#else
luaL_openlib(L, NULL, func, 0);
+#endif
lua_settable(L, -3);
return 0;
}
View
@@ -11,16 +11,16 @@
local string = require("string")
local table = require("table")
local base = _G
-module("ltn12")
+local M = {}
-filter = {}
-source = {}
-sink = {}
-pump = {}
+M.filter = {}
+M.source = {}
+M.sink = {}
+M.pump = {}
-- 2048 seems to be better in windows...
-BLOCKSIZE = 2048
-_VERSION = "LTN12 1.0.1"
+M.BLOCKSIZE = 2048
+M._VERSION = "LTN12 1.0.1"
-----------------------------------------------------------------------------
-- Filter stuff
@@ -89,7 +89,7 @@ end
function source.file(handle, io_err)
if handle then
return function()
- local chunk = handle:read(BLOCKSIZE)
+ local chunk = handle:read(M.BLOCKSIZE)
if not chunk then handle:close() end
return chunk
end
@@ -112,8 +112,8 @@ function source.string(s)
if s then
local i = 1
return function()
- local chunk = string.sub(s, i, i+BLOCKSIZE-1)
- i = i + BLOCKSIZE
+ local chunk = string.sub(s, i, i+M.BLOCKSIZE-1)
+ i = i + M.BLOCKSIZE
if chunk ~= "" then return chunk
else return nil end
end
@@ -290,3 +290,5 @@ function pump.all(src, snk, step)
end
end
+return M
+
View
@@ -87,7 +87,12 @@ static int global_unload(lua_State *L) {
static int base_open(lua_State *L) {
if (socket_open()) {
/* export functions (and leave namespace table on top of stack) */
+#if LUA_VERSION_NUM == 502
+ lua_createtable(L,0,0);
+ luaL_setfuncs(L,func,0);
+#else
luaL_openlib(L, "socket", func, 0);
+#endif
#ifdef LUASOCKET_DEBUG
lua_pushstring(L, "_DEBUG");
lua_pushboolean(L, 1);
View
@@ -83,7 +83,12 @@ static UC b64unbase[256];
\*-------------------------------------------------------------------------*/
MIME_API int luaopen_mime_core(lua_State *L)
{
+#if LUA_VERSION_NUM == 502
+ lua_createtable(L,0,0);
+ luaL_setfuncs(L,func,0);
+#else
luaL_openlib(L, "mime", func, 0);
+#endif
/* make version string available to scripts */
lua_pushstring(L, "_VERSION");
lua_pushstring(L, MIME_VERSION);
Oops, something went wrong.

0 comments on commit 027bc51

Please sign in to comment.