From d3d4156ef9d4d7e934e246dc265138be224f2612 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 20 Mar 2003 23:11:25 +0000 Subject: [PATCH] Completed port to Lua 5.0-beta. --- src/buffer.c | 10 +++++----- src/inet.c | 4 ++-- src/select.c | 2 ++ src/timeout.c | 2 +- src/udp.c | 20 ++++++++++---------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 4260f20..2938b52 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -67,7 +67,7 @@ int buf_send(lua_State *L, p_buf buf) tm_markstart(&base->base_tm); for (arg = 2; arg <= top; arg++) { /* first arg is socket object */ size_t done, len; - cchar *data = luaL_opt_lstr(L, arg, NULL, &len); + cchar *data = luaL_optlstring(L, arg, NULL, &len); if (!data || err != PRIV_DONE) break; err = sendraw(L, buf, data, len, &done); total += done; @@ -111,12 +111,12 @@ int buf_receive(lua_State *L, p_buf buf) top++; } /* make sure we have enough stack space */ - luaL_check_stack(L, top+LUA_MINSTACK, "too many arguments"); + luaL_checkstack(L, top+LUA_MINSTACK, "too many arguments"); /* receive all patterns */ for (arg = 2; arg <= top && err == PRIV_DONE; arg++) { if (!lua_isnumber(L, arg)) { static cchar *patternnames[] = {"*l", "*lu", "*a", "*w", NULL}; - cchar *pattern = luaL_opt_string(L, arg, NULL); + cchar *pattern = luaL_optstring(L, arg, NULL); /* get next pattern */ switch (luaL_findstring(pattern, patternnames)) { case 0: /* DOS line pattern */ @@ -126,10 +126,10 @@ int buf_receive(lua_State *L, p_buf buf) case 2: /* Until closed pattern */ err = recvall(L, buf); break; case 3: /* Word pattern */ - luaL_arg_check(L, 0, arg, "word patterns are deprecated"); + luaL_argcheck(L, 0, arg, "word patterns are deprecated"); break; default: /* else it is an error */ - luaL_arg_check(L, 0, arg, "invalid receive pattern"); + luaL_argcheck(L, 0, arg, "invalid receive pattern"); break; } /* raw pattern */ diff --git a/src/inet.c b/src/inet.c index 3e89e88..eb4124b 100644 --- a/src/inet.c +++ b/src/inet.c @@ -86,7 +86,7 @@ void inet_construct(lua_State *L, p_inet inet) \*-------------------------------------------------------------------------*/ static int inet_lua_toip(lua_State *L) { - cchar *address = luaL_check_string(L, 1); + cchar *address = luaL_checkstring(L, 1); struct in_addr addr; struct hostent *hp; if (inet_aton(address, &addr)) @@ -114,7 +114,7 @@ static int inet_lua_toip(lua_State *L) \*-------------------------------------------------------------------------*/ static int inet_lua_tohostname(lua_State *L) { - cchar *address = luaL_check_string(L, 1); + cchar *address = luaL_checkstring(L, 1); struct in_addr addr; struct hostent *hp; if (inet_aton(address, &addr)) diff --git a/src/select.c b/src/select.c index 5c08730..4dcfd26 100644 --- a/src/select.c +++ b/src/select.c @@ -1,4 +1,6 @@ #include +#include + #include "lspriv.h" #include "lsselect.h" #include "lsfd.h" diff --git a/src/timeout.c b/src/timeout.c index 940ddca..dfece82 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -149,7 +149,7 @@ static int tm_lua_time(lua_State *L) \*-------------------------------------------------------------------------*/ int tm_lua_sleep(lua_State *L) { - double n = luaL_check_number(L, 1); + double n = luaL_checknumber(L, 1); #ifdef WIN32 Sleep(n*1000); #else diff --git a/src/udp.c b/src/udp.c index 29004fd..fd569c6 100644 --- a/src/udp.c +++ b/src/udp.c @@ -135,7 +135,7 @@ static int udp_lua_receive(lua_State *L) { p_udp udp = (p_udp) lua_touserdata(L, 1); unsigned char buffer[UDP_DATAGRAMSIZE]; - size_t got, wanted = (size_t) luaL_opt_number(L, 2, sizeof(buffer)); + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); int err; p_tm tm = &udp->base_tm; wanted = MIN(wanted, sizeof(buffer)); @@ -164,7 +164,7 @@ static int udp_lua_receivefrom(lua_State *L) struct sockaddr_in peer; int peer_len = sizeof(peer); unsigned char buffer[UDP_DATAGRAMSIZE]; - size_t wanted = (size_t) luaL_opt_number(L, 2, sizeof(buffer)); + size_t wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); size_t got; int err; if (udp->udp_connected) luaL_error(L, "receivefrom on connected socket"); @@ -200,7 +200,7 @@ static int udp_lua_send(lua_State *L) p_tm tm = &udp->base_tm; size_t wanted, sent = 0; int err; - cchar *data = luaL_check_lstr(L, 2, &wanted); + cchar *data = luaL_checklstring(L, 2, &wanted); if (!udp->udp_connected) luaL_error(L, "send on unconnected socket"); tm_markstart(tm); err = compat_send(udp->fd, data, wanted, &sent, tm_getremaining(tm)); @@ -224,9 +224,9 @@ static int udp_lua_sendto(lua_State *L) { p_udp udp = (p_udp) lua_touserdata(L, 1); size_t wanted, sent = 0; - cchar *data = luaL_check_lstr(L, 2, &wanted); - cchar *ip = luaL_check_string(L, 3); - ushort port = (ushort) luaL_check_number(L, 4); + cchar *data = luaL_checklstring(L, 2, &wanted); + cchar *ip = luaL_checkstring(L, 3); + ushort port = (ushort) luaL_checknumber(L, 4); p_tm tm = &udp->base_tm; struct sockaddr_in peer; int err; @@ -255,8 +255,8 @@ static int udp_lua_sendto(lua_State *L) static int udp_lua_setsockname(lua_State * L) { p_udp udp = (p_udp) lua_touserdata(L, 1); - cchar *address = luaL_check_string(L, 2); - ushort port = (ushort) luaL_check_number(L, 3); + cchar *address = luaL_checkstring(L, 2); + ushort port = (ushort) luaL_checknumber(L, 3); cchar *err = inet_trybind((p_inet) udp, address, port); if (err) lua_pushstring(L, err); else lua_pushnil(L); @@ -275,8 +275,8 @@ static int udp_lua_setsockname(lua_State * L) static int udp_lua_setpeername(lua_State *L) { p_udp udp = (p_udp) lua_touserdata(L, 1); - cchar *address = luaL_check_string(L, 2); - ushort port = (ushort) luaL_check_number(L, 3); + cchar *address = luaL_checkstring(L, 2); + ushort port = (ushort) luaL_checknumber(L, 3); cchar *err = inet_tryconnect((p_inet) udp, address, port); if (!err) { udp->udp_connected = 1;