Compiles with Lua 5.1.4 and Lua 5.2.0-beta, although the makefile needs sorting out to take maybe a version number and also the local paths need removing.

This commit is contained in:
Liam Devine 2011-07-04 23:31:14 +01:00 committed by Sam Roberts
parent a984607f28
commit e15ed19db6
17 changed files with 70 additions and 49 deletions

View File

@ -8,6 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include "auxiliar.h" #include "auxiliar.h"
#include "lua_typeerror.h"
/*=========================================================================*\ /*=========================================================================*\
* Exported functions * Exported functions
@ -24,7 +25,7 @@ int auxiliar_open(lua_State *L) {
* Creates a new class with given methods * Creates a new class with given methods
* Methods whose names start with __ are passed directly to the metatable. * Methods whose names start with __ are passed directly to the metatable.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func) { void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) {
luaL_newmetatable(L, classname); /* mt */ luaL_newmetatable(L, classname); /* mt */
/* create __index table to place methods */ /* create __index table to place methods */
lua_pushstring(L, "__index"); /* mt,"__index" */ lua_pushstring(L, "__index"); /* mt,"__index" */
@ -81,7 +82,7 @@ void auxiliar_add2group(lua_State *L, const char *classname, const char *groupna
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
int auxiliar_checkboolean(lua_State *L, int objidx) { int auxiliar_checkboolean(lua_State *L, int objidx) {
if (!lua_isboolean(L, objidx)) if (!lua_isboolean(L, objidx))
luaL_typerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); luaL_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN));
return lua_toboolean(L, objidx); return lua_toboolean(L, objidx);
} }

View File

@ -33,7 +33,7 @@
#include "lauxlib.h" #include "lauxlib.h"
int auxiliar_open(lua_State *L); int auxiliar_open(lua_State *L);
void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func); void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func);
void auxiliar_add2group(lua_State *L, const char *classname, const char *group); void auxiliar_add2group(lua_State *L, const char *classname, const char *group);
void auxiliar_setclass(lua_State *L, const char *classname, int objidx); void auxiliar_setclass(lua_State *L, const char *classname, int objidx);
void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx);

View File

@ -231,7 +231,7 @@ static int recvline(p_buffer buf, luaL_Buffer *b) {
pos = 0; pos = 0;
while (pos < count && data[pos] != '\n') { while (pos < count && data[pos] != '\n') {
/* we ignore all \r's */ /* we ignore all \r's */
if (data[pos] != '\r') luaL_putchar(b, data[pos]); if (data[pos] != '\r') luaL_addchar(b, data[pos]);
pos++; pos++;
} }
if (pos < count) { /* found '\n' */ if (pos < count) { /* found '\n' */

View File

@ -21,7 +21,7 @@ static int finalize(lua_State *L);
static int do_nothing(lua_State *L); static int do_nothing(lua_State *L);
/* except functions */ /* except functions */
static luaL_reg func[] = { static luaL_Reg func[] = {
{"newtry", global_newtry}, {"newtry", global_newtry},
{"protect", global_protect}, {"protect", global_protect},
{NULL, NULL} {NULL, NULL}

View File

@ -22,7 +22,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp);
static int inet_global_gethostname(lua_State *L); static int inet_global_gethostname(lua_State *L);
/* DNS functions */ /* DNS functions */
static luaL_reg func[] = { static luaL_Reg func[] = {
{ "toip", inet_global_toip}, { "toip", inet_global_toip},
{ "getaddrinfo", inet_global_getaddrinfo}, { "getaddrinfo", inet_global_getaddrinfo},
{ "tohostname", inet_global_tohostname}, { "tohostname", inet_global_tohostname},

View File

@ -45,7 +45,7 @@ static int base_open(lua_State *L);
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Modules and functions * Modules and functions
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static const luaL_reg mod[] = { static const luaL_Reg mod[] = {
{"auxiliar", auxiliar_open}, {"auxiliar", auxiliar_open},
{"except", except_open}, {"except", except_open},
{"timeout", timeout_open}, {"timeout", timeout_open},
@ -57,7 +57,7 @@ static const luaL_reg mod[] = {
{NULL, NULL} {NULL, NULL}
}; };
static luaL_reg func[] = { static luaL_Reg func[] = {
{"skip", global_skip}, {"skip", global_skip},
{"__unload", global_unload}, {"__unload", global_unload},
{NULL, NULL} {NULL, NULL}

View File

@ -11,7 +11,7 @@
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Current socket library version * Current socket library version
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
#define LUASOCKET_VERSION "LuaSocket 2.1.0" #define LUASOCKET_VERSION "LuaSocket 2.1.1"
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2011 Diego Nehab" #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2011 Diego Nehab"
#define LUASOCKET_AUTHORS "Diego Nehab" #define LUASOCKET_AUTHORS "Diego Nehab"
@ -22,6 +22,10 @@
#define LUASOCKET_API extern #define LUASOCKET_API extern
#endif #endif
#if LUA_VERSION_NUM > 501 & !( defined LUA_COMPAT_MODULE)
# error Lua 5.2 requires LUA_COMPAT_MODULE defined for luaL_openlib
#endif
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Initializes the library. * Initializes the library.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/

View File

@ -2,9 +2,13 @@ PLAT?=macosx
INSTALL_DATA=cp INSTALL_DATA=cp
INSTALL_EXEC=cp INSTALL_EXEC=cp
INSTALL_TOP=/opt/local #INSTALL_TOP=/opt/local
INSTALL_TOP=./
#LUAINC_macosx=/opt/local/include
LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.2.0-beta/src
#LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.1.4/src
LUAINC_macosx=/opt/local/include
LUAINC_linux=/usr/include/lua5.1 LUAINC_linux=/usr/include/lua5.1
LUAINC_win32="../../lua-5.1.3/src" LUAINC_win32="../../lua-5.1.3/src"
LUALIB_win32="../../lua-5.1.3" LUALIB_win32="../../lua-5.1.3"
@ -12,11 +16,15 @@ LUALIB_win32="../../lua-5.1.3"
#------ #------
# Install directories # Install directories
# #
INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/5.1 #INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/5.1
INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/5.1 #INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/5.1
INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/5.2
INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/5.2
INSTALL_SOCKET_SHARE=$(INSTALL_TOP_SHARE)/socket INSTALL_SOCKET_SHARE=$(INSTALL_TOP_SHARE)/socket
INSTALL_SOCKET_LIB=$(INSTALL_TOP_LIB)/socket INSTALL_SOCKET_LIB=$(INSTALL_TOP_LIB)/socket
INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/mime #INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/mime
INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/foo/mime
INSTALL_MIME_LIB=$(INSTALL_TOP_LIB)/mime INSTALL_MIME_LIB=$(INSTALL_TOP_LIB)/mime
#------ #------
@ -30,7 +38,7 @@ PLATS= macosx linux win32
SO_macosx=so SO_macosx=so
O_macosx=o O_macosx=o
CC_macosx=gcc CC_macosx=gcc
DEF_macosx= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN \ DEF_macosx= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN -DLUA_COMPAT_MODULE \
-DLUASOCKET_API='__attribute__((visibility("default")))' \ -DLUASOCKET_API='__attribute__((visibility("default")))' \
-DMIME_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))'
CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \
@ -84,7 +92,7 @@ SOCKET_win32=wsocket.obj
# #
SO=$(SO_$(PLAT)) SO=$(SO_$(PLAT))
O=$(O_$(PLAT)) O=$(O_$(PLAT))
SOCKET_V=2.0.3 SOCKET_V=2.1.1
MIME_V=1.0.3 MIME_V=1.0.3
SOCKET_SO=socket.$(SO).$(SOCKET_V) SOCKET_SO=socket.$(SO).$(SOCKET_V)
MIME_SO=mime.$(SO).$(MIME_V) MIME_SO=mime.$(SO).$(MIME_V)
@ -117,7 +125,8 @@ SOCKET_OBJS= \
except.$(O) \ except.$(O) \
select.$(O) \ select.$(O) \
tcp.$(O) \ tcp.$(O) \
udp.$(O) udp.$(O) \
lua_typeerror.$(O)
#------ #------
# Modules belonging mime-core # Modules belonging mime-core
@ -135,7 +144,8 @@ UNIX_OBJS=\
timeout.$(O) \ timeout.$(O) \
io.$(O) \ io.$(O) \
usocket.$(O) \ usocket.$(O) \
unix.$(O) unix.$(O) \
lua_typeerror.$(O)
#------ #------
# Files to install # Files to install

View File

@ -48,7 +48,7 @@ static size_t qpencode(UC c, UC *input, size_t size,
static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer); static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer);
/* code support functions */ /* code support functions */
static luaL_reg func[] = { static luaL_Reg func[] = {
{ "dot", mime_global_dot }, { "dot", mime_global_dot },
{ "b64", mime_global_b64 }, { "b64", mime_global_b64 },
{ "eol", mime_global_eol }, { "eol", mime_global_eol },
@ -135,7 +135,7 @@ static int mime_global_wrp(lua_State *L)
left = length; left = length;
luaL_addstring(&buffer, CRLF); luaL_addstring(&buffer, CRLF);
} }
luaL_putchar(&buffer, *input); luaL_addchar(&buffer, *input);
left--; left--;
break; break;
} }
@ -374,9 +374,9 @@ static void qpsetup(UC *cl, UC *unbase)
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static void qpquote(UC c, luaL_Buffer *buffer) static void qpquote(UC c, luaL_Buffer *buffer)
{ {
luaL_putchar(buffer, '='); luaL_addchar(buffer, '=');
luaL_putchar(buffer, qpbase[c >> 4]); luaL_addchar(buffer, qpbase[c >> 4]);
luaL_putchar(buffer, qpbase[c & 0x0F]); luaL_addchar(buffer, qpbase[c & 0x0F]);
} }
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
@ -406,7 +406,7 @@ static size_t qpencode(UC c, UC *input, size_t size,
qpquote(input[0], buffer); qpquote(input[0], buffer);
luaL_addstring(buffer, marker); luaL_addstring(buffer, marker);
return 0; return 0;
} else luaL_putchar(buffer, input[0]); } else luaL_addchar(buffer, input[0]);
break; break;
/* might have to be quoted always */ /* might have to be quoted always */
case QP_QUOTED: case QP_QUOTED:
@ -414,7 +414,7 @@ static size_t qpencode(UC c, UC *input, size_t size,
break; break;
/* might never have to be quoted */ /* might never have to be quoted */
default: default:
luaL_putchar(buffer, input[0]); luaL_addchar(buffer, input[0]);
break; break;
} }
input[0] = input[1]; input[1] = input[2]; input[0] = input[1]; input[1] = input[2];
@ -430,7 +430,7 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)
{ {
size_t i; size_t i;
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
if (qpclass[input[i]] == QP_PLAIN) luaL_putchar(buffer, input[i]); if (qpclass[input[i]] == QP_PLAIN) luaL_addchar(buffer, input[i]);
else qpquote(input[i], buffer); else qpquote(input[i], buffer);
} }
if (size > 0) luaL_addstring(buffer, EQCRLF); if (size > 0) luaL_addstring(buffer, EQCRLF);
@ -500,7 +500,7 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
c = qpunbase[input[1]]; d = qpunbase[input[2]]; c = qpunbase[input[1]]; d = qpunbase[input[2]];
/* if it is an invalid, do not decode */ /* if it is an invalid, do not decode */
if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3); if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3);
else luaL_putchar(buffer, (c << 4) + d); else luaL_addchar(buffer, (c << 4) + d);
return 0; return 0;
case '\r': case '\r':
if (size < 2) return size; if (size < 2) return size;
@ -508,7 +508,7 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
return 0; return 0;
default: default:
if (input[0] == '\t' || (input[0] > 31 && input[0] < 127)) if (input[0] == '\t' || (input[0] > 31 && input[0] < 127))
luaL_putchar(buffer, input[0]); luaL_addchar(buffer, input[0]);
return 0; return 0;
} }
} }
@ -593,7 +593,7 @@ static int mime_global_qpwrp(lua_State *L)
left = length; left = length;
luaL_addstring(&buffer, EQCRLF); luaL_addstring(&buffer, EQCRLF);
} }
luaL_putchar(&buffer, *input); luaL_addchar(&buffer, *input);
left--; left--;
break; break;
default: default:
@ -601,7 +601,7 @@ static int mime_global_qpwrp(lua_State *L)
left = length; left = length;
luaL_addstring(&buffer, EQCRLF); luaL_addstring(&buffer, EQCRLF);
} }
luaL_putchar(&buffer, *input); luaL_addchar(&buffer, *input);
left--; left--;
break; break;
} }
@ -636,7 +636,7 @@ static int eolprocess(int c, int last, const char *marker,
return c; return c;
} }
} else { } else {
luaL_putchar(buffer, c); luaL_addchar(buffer, c);
return 0; return 0;
} }
} }
@ -676,7 +676,7 @@ static int mime_global_eol(lua_State *L)
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static size_t dot(int c, size_t state, luaL_Buffer *buffer) static size_t dot(int c, size_t state, luaL_Buffer *buffer)
{ {
luaL_putchar(buffer, c); luaL_addchar(buffer, c);
switch (c) { switch (c) {
case '\r': case '\r':
return 1; return 1;
@ -684,7 +684,7 @@ static size_t dot(int c, size_t state, luaL_Buffer *buffer)
return (state == 1)? 2: 0; return (state == 1)? 2: 0;
case '.': case '.':
if (state == 2) if (state == 2)
luaL_putchar(buffer, '.'); luaL_addchar(buffer, '.');
default: default:
return 0; return 0;
} }

View File

@ -11,6 +11,7 @@
#include "auxiliar.h" #include "auxiliar.h"
#include "options.h" #include "options.h"
#include "inet.h" #include "inet.h"
#include "lua_typeerror.h"
/*=========================================================================*\ /*=========================================================================*\
* Internal functions prototypes * Internal functions prototypes
@ -99,7 +100,7 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
int opt_set_linger(lua_State *L, p_socket ps) int opt_set_linger(lua_State *L, p_socket ps)
{ {
struct linger li; /* obj, name, table */ struct linger li; /* obj, name, table */
if (!lua_istable(L, 3)) luaL_typerror(L, 3, lua_typename(L, LUA_TTABLE)); if (!lua_istable(L, 3)) luaL_typeerror(L, 3, lua_typename(L, LUA_TTABLE));
lua_pushstring(L, "on"); lua_pushstring(L, "on");
lua_gettable(L, 3); lua_gettable(L, 3);
if (!lua_isboolean(L, -1)) if (!lua_isboolean(L, -1))
@ -165,7 +166,7 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps)
static int opt_setmembership(lua_State *L, p_socket ps, int level, int name) static int opt_setmembership(lua_State *L, p_socket ps, int level, int name)
{ {
struct ip_mreq val; /* obj, name, table */ struct ip_mreq val; /* obj, name, table */
if (!lua_istable(L, 3)) luaL_typerror(L, 3, lua_typename(L, LUA_TTABLE)); if (!lua_istable(L, 3)) luaL_typeerror(L, 3, lua_typename(L, LUA_TTABLE));
lua_pushstring(L, "multiaddr"); lua_pushstring(L, "multiaddr");
lua_gettable(L, 3); lua_gettable(L, 3);
if (!lua_isstring(L, -1)) if (!lua_isstring(L, -1))

View File

@ -27,7 +27,7 @@ static void make_assoc(lua_State *L, int tab);
static int global_select(lua_State *L); static int global_select(lua_State *L);
/* functions in library namespace */ /* functions in library namespace */
static luaL_reg func[] = { static luaL_Reg func[] = {
{"select", global_select}, {"select", global_select},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -40,7 +40,7 @@ static int meth_setfd(lua_State *L);
static int meth_dirty(lua_State *L); static int meth_dirty(lua_State *L);
/* tcp object methods */ /* tcp object methods */
static luaL_reg tcp_methods[] = { static luaL_Reg tcp_methods[] = {
{"__gc", meth_close}, {"__gc", meth_close},
{"__tostring", auxiliar_tostring}, {"__tostring", auxiliar_tostring},
{"accept", meth_accept}, {"accept", meth_accept},
@ -76,7 +76,7 @@ static t_opt optset[] = {
}; };
/* functions in library namespace */ /* functions in library namespace */
static luaL_reg func[] = { static luaL_Reg func[] = {
{"tcp", global_create}, {"tcp", global_create},
{"tcp6", global_create6}, {"tcp6", global_create6},
{"connect6", global_connect6}, {"connect6", global_connect6},

View File

@ -35,7 +35,7 @@
static int timeout_lua_gettime(lua_State *L); static int timeout_lua_gettime(lua_State *L);
static int timeout_lua_sleep(lua_State *L); static int timeout_lua_sleep(lua_State *L);
static luaL_reg func[] = { static luaL_Reg func[] = {
{ "gettime", timeout_lua_gettime }, { "gettime", timeout_lua_gettime },
{ "sleep", timeout_lua_sleep }, { "sleep", timeout_lua_sleep },
{ NULL, NULL } { NULL, NULL }

View File

@ -45,7 +45,7 @@ static int meth_setfd(lua_State *L);
static int meth_dirty(lua_State *L); static int meth_dirty(lua_State *L);
/* udp object methods */ /* udp object methods */
static luaL_reg udp_methods[] = { static luaL_Reg udp_methods[] = {
{"__gc", meth_close}, {"__gc", meth_close},
{"__tostring", auxiliar_tostring}, {"__tostring", auxiliar_tostring},
{"close", meth_close}, {"close", meth_close},
@ -89,7 +89,7 @@ static t_opt optget[] = {
}; };
/* functions in library namespace */ /* functions in library namespace */
static luaL_reg func[] = { static luaL_Reg func[] = {
{"udp", global_create}, {"udp", global_create},
{"udp6", global_create6}, {"udp6", global_create6},
{NULL, NULL} {NULL, NULL}

View File

@ -39,7 +39,7 @@ static const char *unix_tryconnect(p_unix un, const char *path);
static const char *unix_trybind(p_unix un, const char *path); static const char *unix_trybind(p_unix un, const char *path);
/* unix object methods */ /* unix object methods */
static luaL_reg un[] = { static luaL_Reg un[] = {
{"__gc", meth_close}, {"__gc", meth_close},
{"__tostring", auxiliar_tostring}, {"__tostring", auxiliar_tostring},
{"accept", meth_accept}, {"accept", meth_accept},
@ -71,7 +71,7 @@ static t_opt optset[] = {
}; };
/* our socket creation function */ /* our socket creation function */
static luaL_reg func[] = { static luaL_Reg func[] = {
{"unix", global_create}, {"unix", global_create},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -4,8 +4,7 @@ host = host or "localhost"
port = port or "8383" port = port or "8383"
function printf(...) function printf(...)
local s = string.format(unpack(arg)) io.stderr:write(string.format(...))
io.stderr:write(s)
end end
function pass(...) function pass(...)
@ -21,12 +20,12 @@ function fail(...)
end end
function warn(...) function warn(...)
local s = string.format(unpack(arg)) local s = string.format(...)
io.stderr:write("WARNING: ", s, "\n") io.stderr:write("WARNING: ", s, "\n")
end end
function remote(...) function remote(...)
local s = string.format(unpack(arg)) local s = string.format(...)
s = string.gsub(s, "\n", ";") s = string.gsub(s, "\n", ";")
s = string.gsub(s, "%s+", " ") s = string.gsub(s, "%s+", " ")
s = string.gsub(s, "^%s*", "") s = string.gsub(s, "^%s*", "")
@ -141,6 +140,9 @@ remote "data:send(str); data:close()"
end end
------------------------------------------------------------------------ ------------------------------------------------------------------------
if not math.mod then
math.mod = math.fmod
end
function test_asciiline(len) function test_asciiline(len)
reconnect() reconnect()
io.stderr:write("length " .. len .. ": ") io.stderr:write("length " .. len .. ": ")
@ -445,7 +447,10 @@ end
------------------------------------------------------------------------ ------------------------------------------------------------------------
function rebind_test() function rebind_test()
local c = socket.bind("localhost", 0) local c ,c1 = socket.bind("localhost", 0)
if not c then pass ("failed to bind! " .. c .. ' ' .. c1) return end
assert(c,c1)
local i, p = c:getsockname() local i, p = c:getsockname()
local s, e = socket.tcp() local s, e = socket.tcp()
assert(s, e) assert(s, e)

View File

@ -10,6 +10,6 @@ while 1 do
command = assert(control:receive()); command = assert(control:receive());
assert(control:send(ack)); assert(control:send(ack));
print(command); print(command);
(loadstring(command))(); (load(command))();
end end
end end