mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-11-16 02:08:21 +01:00
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:
parent
a984607f28
commit
e15ed19db6
@ -8,6 +8,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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' */
|
||||
|
@ -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}
|
||||
|
@ -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},
|
||||
|
@ -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}
|
||||
|
@ -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.
|
||||
\*-------------------------------------------------------------------------*/
|
||||
|
28
src/makefile
28
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
|
||||
|
30
src/mime.c
30
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;
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -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}
|
||||
};
|
||||
|
@ -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},
|
||||
|
@ -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 }
|
||||
|
@ -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}
|
||||
|
@ -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}
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -10,6 +10,6 @@ while 1 do
|
||||
command = assert(control:receive());
|
||||
assert(control:send(ack));
|
||||
print(command);
|
||||
(loadstring(command))();
|
||||
(load(command))();
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user