diff --git a/src/auxiliar.c b/src/auxiliar.c index 9514970..3396fc1 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -8,6 +8,7 @@ #include #include "auxiliar.h" +#include "lua_typeerror.h" /*=========================================================================*\ * Exported functions @@ -24,7 +25,7 @@ int auxiliar_open(lua_State *L) { * Creates a new class with given methods * 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 */ /* create __index table to place methods */ 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) { 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); } diff --git a/src/auxiliar.h b/src/auxiliar.h index 57a2ecc..c53b39e 100644 --- a/src/auxiliar.h +++ b/src/auxiliar.h @@ -33,7 +33,7 @@ #include "lauxlib.h" 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_setclass(lua_State *L, const char *classname, int objidx); void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); diff --git a/src/buffer.c b/src/buffer.c index fbe00eb..8d90598 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -231,7 +231,7 @@ static int recvline(p_buffer buf, luaL_Buffer *b) { pos = 0; while (pos < count && data[pos] != '\n') { /* we ignore all \r's */ - if (data[pos] != '\r') luaL_putchar(b, data[pos]); + if (data[pos] != '\r') luaL_addchar(b, data[pos]); pos++; } if (pos < count) { /* found '\n' */ diff --git a/src/except.c b/src/except.c index 5faa5be..97c00a3 100644 --- a/src/except.c +++ b/src/except.c @@ -21,7 +21,7 @@ static int finalize(lua_State *L); static int do_nothing(lua_State *L); /* except functions */ -static luaL_reg func[] = { +static luaL_Reg func[] = { {"newtry", global_newtry}, {"protect", global_protect}, {NULL, NULL} diff --git a/src/inet.c b/src/inet.c index 571b838..dc24390 100644 --- a/src/inet.c +++ b/src/inet.c @@ -22,7 +22,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp); static int inet_global_gethostname(lua_State *L); /* DNS functions */ -static luaL_reg func[] = { +static luaL_Reg func[] = { { "toip", inet_global_toip}, { "getaddrinfo", inet_global_getaddrinfo}, { "tohostname", inet_global_tohostname}, diff --git a/src/luasocket.c b/src/luasocket.c index 3b29e8e..b43114e 100644 --- a/src/luasocket.c +++ b/src/luasocket.c @@ -45,7 +45,7 @@ static int base_open(lua_State *L); /*-------------------------------------------------------------------------*\ * Modules and functions \*-------------------------------------------------------------------------*/ -static const luaL_reg mod[] = { +static const luaL_Reg mod[] = { {"auxiliar", auxiliar_open}, {"except", except_open}, {"timeout", timeout_open}, @@ -57,7 +57,7 @@ static const luaL_reg mod[] = { {NULL, NULL} }; -static luaL_reg func[] = { +static luaL_Reg func[] = { {"skip", global_skip}, {"__unload", global_unload}, {NULL, NULL} diff --git a/src/luasocket.h b/src/luasocket.h index 3949421..608ff7b 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -11,7 +11,7 @@ /*-------------------------------------------------------------------------*\ * 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_AUTHORS "Diego Nehab" @@ -22,6 +22,10 @@ #define LUASOCKET_API extern #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. \*-------------------------------------------------------------------------*/ diff --git a/src/makefile b/src/makefile index 9768ba1..b7c22da 100644 --- a/src/makefile +++ b/src/makefile @@ -2,9 +2,13 @@ PLAT?=macosx INSTALL_DATA=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_win32="../../lua-5.1.3/src" LUALIB_win32="../../lua-5.1.3" @@ -12,11 +16,15 @@ LUALIB_win32="../../lua-5.1.3" #------ # Install directories # -INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/5.1 -INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/5.1 +#INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/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_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 #------ @@ -30,7 +38,7 @@ PLATS= macosx linux win32 SO_macosx=so O_macosx=o 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")))' \ -DMIME_API='__attribute__((visibility("default")))' CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ @@ -84,7 +92,7 @@ SOCKET_win32=wsocket.obj # SO=$(SO_$(PLAT)) O=$(O_$(PLAT)) -SOCKET_V=2.0.3 +SOCKET_V=2.1.1 MIME_V=1.0.3 SOCKET_SO=socket.$(SO).$(SOCKET_V) MIME_SO=mime.$(SO).$(MIME_V) @@ -117,7 +125,8 @@ SOCKET_OBJS= \ except.$(O) \ select.$(O) \ tcp.$(O) \ - udp.$(O) + udp.$(O) \ + lua_typeerror.$(O) #------ # Modules belonging mime-core @@ -135,7 +144,8 @@ UNIX_OBJS=\ timeout.$(O) \ io.$(O) \ usocket.$(O) \ - unix.$(O) + unix.$(O) \ + lua_typeerror.$(O) #------ # Files to install diff --git a/src/mime.c b/src/mime.c index a1d7065..023559f 100644 --- a/src/mime.c +++ b/src/mime.c @@ -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); /* code support functions */ -static luaL_reg func[] = { +static luaL_Reg func[] = { { "dot", mime_global_dot }, { "b64", mime_global_b64 }, { "eol", mime_global_eol }, @@ -135,7 +135,7 @@ static int mime_global_wrp(lua_State *L) left = length; luaL_addstring(&buffer, CRLF); } - luaL_putchar(&buffer, *input); + luaL_addchar(&buffer, *input); left--; break; } @@ -374,9 +374,9 @@ static void qpsetup(UC *cl, UC *unbase) \*-------------------------------------------------------------------------*/ static void qpquote(UC c, luaL_Buffer *buffer) { - luaL_putchar(buffer, '='); - luaL_putchar(buffer, qpbase[c >> 4]); - luaL_putchar(buffer, qpbase[c & 0x0F]); + luaL_addchar(buffer, '='); + luaL_addchar(buffer, qpbase[c >> 4]); + 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); luaL_addstring(buffer, marker); return 0; - } else luaL_putchar(buffer, input[0]); + } else luaL_addchar(buffer, input[0]); break; /* might have to be quoted always */ case QP_QUOTED: @@ -414,7 +414,7 @@ static size_t qpencode(UC c, UC *input, size_t size, break; /* might never have to be quoted */ default: - luaL_putchar(buffer, input[0]); + luaL_addchar(buffer, input[0]); break; } 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; 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); } 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]]; /* if it is an invalid, do not decode */ 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; case '\r': 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; default: if (input[0] == '\t' || (input[0] > 31 && input[0] < 127)) - luaL_putchar(buffer, input[0]); + luaL_addchar(buffer, input[0]); return 0; } } @@ -593,7 +593,7 @@ static int mime_global_qpwrp(lua_State *L) left = length; luaL_addstring(&buffer, EQCRLF); } - luaL_putchar(&buffer, *input); + luaL_addchar(&buffer, *input); left--; break; default: @@ -601,7 +601,7 @@ static int mime_global_qpwrp(lua_State *L) left = length; luaL_addstring(&buffer, EQCRLF); } - luaL_putchar(&buffer, *input); + luaL_addchar(&buffer, *input); left--; break; } @@ -636,7 +636,7 @@ static int eolprocess(int c, int last, const char *marker, return c; } } else { - luaL_putchar(buffer, c); + luaL_addchar(buffer, c); 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) { - luaL_putchar(buffer, c); + luaL_addchar(buffer, c); switch (c) { case '\r': return 1; @@ -684,7 +684,7 @@ static size_t dot(int c, size_t state, luaL_Buffer *buffer) return (state == 1)? 2: 0; case '.': if (state == 2) - luaL_putchar(buffer, '.'); + luaL_addchar(buffer, '.'); default: return 0; } diff --git a/src/options.c b/src/options.c index 281a00f..801adf9 100644 --- a/src/options.c +++ b/src/options.c @@ -11,6 +11,7 @@ #include "auxiliar.h" #include "options.h" #include "inet.h" +#include "lua_typeerror.h" /*=========================================================================*\ * 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) { 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_gettable(L, 3); 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) { 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_gettable(L, 3); if (!lua_isstring(L, -1)) diff --git a/src/select.c b/src/select.c index 0931b73..87b5dc2 100644 --- a/src/select.c +++ b/src/select.c @@ -27,7 +27,7 @@ static void make_assoc(lua_State *L, int tab); static int global_select(lua_State *L); /* functions in library namespace */ -static luaL_reg func[] = { +static luaL_Reg func[] = { {"select", global_select}, {NULL, NULL} }; diff --git a/src/tcp.c b/src/tcp.c index b069136..19ee73c 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -40,7 +40,7 @@ static int meth_setfd(lua_State *L); static int meth_dirty(lua_State *L); /* tcp object methods */ -static luaL_reg tcp_methods[] = { +static luaL_Reg tcp_methods[] = { {"__gc", meth_close}, {"__tostring", auxiliar_tostring}, {"accept", meth_accept}, @@ -76,7 +76,7 @@ static t_opt optset[] = { }; /* functions in library namespace */ -static luaL_reg func[] = { +static luaL_Reg func[] = { {"tcp", global_create}, {"tcp6", global_create6}, {"connect6", global_connect6}, diff --git a/src/timeout.c b/src/timeout.c index cc7309c..a3f1318 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -35,7 +35,7 @@ static int timeout_lua_gettime(lua_State *L); static int timeout_lua_sleep(lua_State *L); -static luaL_reg func[] = { +static luaL_Reg func[] = { { "gettime", timeout_lua_gettime }, { "sleep", timeout_lua_sleep }, { NULL, NULL } diff --git a/src/udp.c b/src/udp.c index cc04fc8..13007fb 100644 --- a/src/udp.c +++ b/src/udp.c @@ -45,7 +45,7 @@ static int meth_setfd(lua_State *L); static int meth_dirty(lua_State *L); /* udp object methods */ -static luaL_reg udp_methods[] = { +static luaL_Reg udp_methods[] = { {"__gc", meth_close}, {"__tostring", auxiliar_tostring}, {"close", meth_close}, @@ -89,7 +89,7 @@ static t_opt optget[] = { }; /* functions in library namespace */ -static luaL_reg func[] = { +static luaL_Reg func[] = { {"udp", global_create}, {"udp6", global_create6}, {NULL, NULL} diff --git a/src/unix.c b/src/unix.c index 6962517..b08d325 100644 --- a/src/unix.c +++ b/src/unix.c @@ -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); /* unix object methods */ -static luaL_reg un[] = { +static luaL_Reg un[] = { {"__gc", meth_close}, {"__tostring", auxiliar_tostring}, {"accept", meth_accept}, @@ -71,7 +71,7 @@ static t_opt optset[] = { }; /* our socket creation function */ -static luaL_reg func[] = { +static luaL_Reg func[] = { {"unix", global_create}, {NULL, NULL} }; diff --git a/test/testclnt.lua b/test/testclnt.lua index 4c2f211..ad3741a 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua @@ -4,8 +4,7 @@ host = host or "localhost" port = port or "8383" function printf(...) - local s = string.format(unpack(arg)) - io.stderr:write(s) + io.stderr:write(string.format(...)) end function pass(...) @@ -21,12 +20,12 @@ function fail(...) end function warn(...) - local s = string.format(unpack(arg)) + local s = string.format(...) io.stderr:write("WARNING: ", s, "\n") end function remote(...) - local s = string.format(unpack(arg)) + local s = string.format(...) s = string.gsub(s, "\n", ";") s = string.gsub(s, "%s+", " ") s = string.gsub(s, "^%s*", "") @@ -141,6 +140,9 @@ remote "data:send(str); data:close()" end ------------------------------------------------------------------------ +if not math.mod then + math.mod = math.fmod +end function test_asciiline(len) reconnect() io.stderr:write("length " .. len .. ": ") @@ -445,7 +447,10 @@ end ------------------------------------------------------------------------ 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 s, e = socket.tcp() assert(s, e) diff --git a/test/testsrvr.lua b/test/testsrvr.lua index f1972c2..7ddff6e 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua @@ -10,6 +10,6 @@ while 1 do command = assert(control:receive()); assert(control:send(ack)); print(command); - (loadstring(command))(); + (load(command))(); end end