mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-11-08 06:18:21 +01:00
Completed port to Lua 5.0-beta.
This commit is contained in:
parent
53857360bb
commit
d3d4156ef9
10
src/buffer.c
10
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 */
|
||||
|
@ -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))
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#include "lspriv.h"
|
||||
#include "lsselect.h"
|
||||
#include "lsfd.h"
|
||||
|
@ -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
|
||||
|
20
src/udp.c
20
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;
|
||||
|
Loading…
Reference in New Issue
Block a user