diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-20 23:11:25 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-20 23:11:25 +0000 |
| commit | d3d4156ef9d4d7e934e246dc265138be224f2612 (patch) | |
| tree | 9edfb76ad844a233596b472ade7182550831fa6c /src | |
| parent | 53857360bb1ca9cd2080b69d930763ae59db9b06 (diff) | |
| download | luasocket-d3d4156ef9d4d7e934e246dc265138be224f2612.tar.gz luasocket-d3d4156ef9d4d7e934e246dc265138be224f2612.tar.bz2 luasocket-d3d4156ef9d4d7e934e246dc265138be224f2612.zip | |
Completed port to Lua 5.0-beta.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.c | 10 | ||||
| -rw-r--r-- | src/inet.c | 4 | ||||
| -rw-r--r-- | src/select.c | 2 | ||||
| -rw-r--r-- | src/timeout.c | 2 | ||||
| -rw-r--r-- | 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) | |||
| 67 | tm_markstart(&base->base_tm); | 67 | tm_markstart(&base->base_tm); |
| 68 | for (arg = 2; arg <= top; arg++) { /* first arg is socket object */ | 68 | for (arg = 2; arg <= top; arg++) { /* first arg is socket object */ |
| 69 | size_t done, len; | 69 | size_t done, len; |
| 70 | cchar *data = luaL_opt_lstr(L, arg, NULL, &len); | 70 | cchar *data = luaL_optlstring(L, arg, NULL, &len); |
| 71 | if (!data || err != PRIV_DONE) break; | 71 | if (!data || err != PRIV_DONE) break; |
| 72 | err = sendraw(L, buf, data, len, &done); | 72 | err = sendraw(L, buf, data, len, &done); |
| 73 | total += done; | 73 | total += done; |
| @@ -111,12 +111,12 @@ int buf_receive(lua_State *L, p_buf buf) | |||
| 111 | top++; | 111 | top++; |
| 112 | } | 112 | } |
| 113 | /* make sure we have enough stack space */ | 113 | /* make sure we have enough stack space */ |
| 114 | luaL_check_stack(L, top+LUA_MINSTACK, "too many arguments"); | 114 | luaL_checkstack(L, top+LUA_MINSTACK, "too many arguments"); |
| 115 | /* receive all patterns */ | 115 | /* receive all patterns */ |
| 116 | for (arg = 2; arg <= top && err == PRIV_DONE; arg++) { | 116 | for (arg = 2; arg <= top && err == PRIV_DONE; arg++) { |
| 117 | if (!lua_isnumber(L, arg)) { | 117 | if (!lua_isnumber(L, arg)) { |
| 118 | static cchar *patternnames[] = {"*l", "*lu", "*a", "*w", NULL}; | 118 | static cchar *patternnames[] = {"*l", "*lu", "*a", "*w", NULL}; |
| 119 | cchar *pattern = luaL_opt_string(L, arg, NULL); | 119 | cchar *pattern = luaL_optstring(L, arg, NULL); |
| 120 | /* get next pattern */ | 120 | /* get next pattern */ |
| 121 | switch (luaL_findstring(pattern, patternnames)) { | 121 | switch (luaL_findstring(pattern, patternnames)) { |
| 122 | case 0: /* DOS line pattern */ | 122 | case 0: /* DOS line pattern */ |
| @@ -126,10 +126,10 @@ int buf_receive(lua_State *L, p_buf buf) | |||
| 126 | case 2: /* Until closed pattern */ | 126 | case 2: /* Until closed pattern */ |
| 127 | err = recvall(L, buf); break; | 127 | err = recvall(L, buf); break; |
| 128 | case 3: /* Word pattern */ | 128 | case 3: /* Word pattern */ |
| 129 | luaL_arg_check(L, 0, arg, "word patterns are deprecated"); | 129 | luaL_argcheck(L, 0, arg, "word patterns are deprecated"); |
| 130 | break; | 130 | break; |
| 131 | default: /* else it is an error */ | 131 | default: /* else it is an error */ |
| 132 | luaL_arg_check(L, 0, arg, "invalid receive pattern"); | 132 | luaL_argcheck(L, 0, arg, "invalid receive pattern"); |
| 133 | break; | 133 | break; |
| 134 | } | 134 | } |
| 135 | /* raw pattern */ | 135 | /* raw pattern */ |
| @@ -86,7 +86,7 @@ void inet_construct(lua_State *L, p_inet inet) | |||
| 86 | \*-------------------------------------------------------------------------*/ | 86 | \*-------------------------------------------------------------------------*/ |
| 87 | static int inet_lua_toip(lua_State *L) | 87 | static int inet_lua_toip(lua_State *L) |
| 88 | { | 88 | { |
| 89 | cchar *address = luaL_check_string(L, 1); | 89 | cchar *address = luaL_checkstring(L, 1); |
| 90 | struct in_addr addr; | 90 | struct in_addr addr; |
| 91 | struct hostent *hp; | 91 | struct hostent *hp; |
| 92 | if (inet_aton(address, &addr)) | 92 | if (inet_aton(address, &addr)) |
| @@ -114,7 +114,7 @@ static int inet_lua_toip(lua_State *L) | |||
| 114 | \*-------------------------------------------------------------------------*/ | 114 | \*-------------------------------------------------------------------------*/ |
| 115 | static int inet_lua_tohostname(lua_State *L) | 115 | static int inet_lua_tohostname(lua_State *L) |
| 116 | { | 116 | { |
| 117 | cchar *address = luaL_check_string(L, 1); | 117 | cchar *address = luaL_checkstring(L, 1); |
| 118 | struct in_addr addr; | 118 | struct in_addr addr; |
| 119 | struct hostent *hp; | 119 | struct hostent *hp; |
| 120 | if (inet_aton(address, &addr)) | 120 | 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 @@ | |||
| 1 | #include <lua.h> | 1 | #include <lua.h> |
| 2 | #include <lauxlib.h> | ||
| 3 | |||
| 2 | #include "lspriv.h" | 4 | #include "lspriv.h" |
| 3 | #include "lsselect.h" | 5 | #include "lsselect.h" |
| 4 | #include "lsfd.h" | 6 | #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) | |||
| 149 | \*-------------------------------------------------------------------------*/ | 149 | \*-------------------------------------------------------------------------*/ |
| 150 | int tm_lua_sleep(lua_State *L) | 150 | int tm_lua_sleep(lua_State *L) |
| 151 | { | 151 | { |
| 152 | double n = luaL_check_number(L, 1); | 152 | double n = luaL_checknumber(L, 1); |
| 153 | #ifdef WIN32 | 153 | #ifdef WIN32 |
| 154 | Sleep(n*1000); | 154 | Sleep(n*1000); |
| 155 | #else | 155 | #else |
| @@ -135,7 +135,7 @@ static int udp_lua_receive(lua_State *L) | |||
| 135 | { | 135 | { |
| 136 | p_udp udp = (p_udp) lua_touserdata(L, 1); | 136 | p_udp udp = (p_udp) lua_touserdata(L, 1); |
| 137 | unsigned char buffer[UDP_DATAGRAMSIZE]; | 137 | unsigned char buffer[UDP_DATAGRAMSIZE]; |
| 138 | size_t got, wanted = (size_t) luaL_opt_number(L, 2, sizeof(buffer)); | 138 | size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); |
| 139 | int err; | 139 | int err; |
| 140 | p_tm tm = &udp->base_tm; | 140 | p_tm tm = &udp->base_tm; |
| 141 | wanted = MIN(wanted, sizeof(buffer)); | 141 | wanted = MIN(wanted, sizeof(buffer)); |
| @@ -164,7 +164,7 @@ static int udp_lua_receivefrom(lua_State *L) | |||
| 164 | struct sockaddr_in peer; | 164 | struct sockaddr_in peer; |
| 165 | int peer_len = sizeof(peer); | 165 | int peer_len = sizeof(peer); |
| 166 | unsigned char buffer[UDP_DATAGRAMSIZE]; | 166 | unsigned char buffer[UDP_DATAGRAMSIZE]; |
| 167 | size_t wanted = (size_t) luaL_opt_number(L, 2, sizeof(buffer)); | 167 | size_t wanted = (size_t) luaL_optnumber(L, 2, sizeof(buffer)); |
| 168 | size_t got; | 168 | size_t got; |
| 169 | int err; | 169 | int err; |
| 170 | if (udp->udp_connected) luaL_error(L, "receivefrom on connected socket"); | 170 | if (udp->udp_connected) luaL_error(L, "receivefrom on connected socket"); |
| @@ -200,7 +200,7 @@ static int udp_lua_send(lua_State *L) | |||
| 200 | p_tm tm = &udp->base_tm; | 200 | p_tm tm = &udp->base_tm; |
| 201 | size_t wanted, sent = 0; | 201 | size_t wanted, sent = 0; |
| 202 | int err; | 202 | int err; |
| 203 | cchar *data = luaL_check_lstr(L, 2, &wanted); | 203 | cchar *data = luaL_checklstring(L, 2, &wanted); |
| 204 | if (!udp->udp_connected) luaL_error(L, "send on unconnected socket"); | 204 | if (!udp->udp_connected) luaL_error(L, "send on unconnected socket"); |
| 205 | tm_markstart(tm); | 205 | tm_markstart(tm); |
| 206 | err = compat_send(udp->fd, data, wanted, &sent, tm_getremaining(tm)); | 206 | err = compat_send(udp->fd, data, wanted, &sent, tm_getremaining(tm)); |
| @@ -224,9 +224,9 @@ static int udp_lua_sendto(lua_State *L) | |||
| 224 | { | 224 | { |
| 225 | p_udp udp = (p_udp) lua_touserdata(L, 1); | 225 | p_udp udp = (p_udp) lua_touserdata(L, 1); |
| 226 | size_t wanted, sent = 0; | 226 | size_t wanted, sent = 0; |
| 227 | cchar *data = luaL_check_lstr(L, 2, &wanted); | 227 | cchar *data = luaL_checklstring(L, 2, &wanted); |
| 228 | cchar *ip = luaL_check_string(L, 3); | 228 | cchar *ip = luaL_checkstring(L, 3); |
| 229 | ushort port = (ushort) luaL_check_number(L, 4); | 229 | ushort port = (ushort) luaL_checknumber(L, 4); |
| 230 | p_tm tm = &udp->base_tm; | 230 | p_tm tm = &udp->base_tm; |
| 231 | struct sockaddr_in peer; | 231 | struct sockaddr_in peer; |
| 232 | int err; | 232 | int err; |
| @@ -255,8 +255,8 @@ static int udp_lua_sendto(lua_State *L) | |||
| 255 | static int udp_lua_setsockname(lua_State * L) | 255 | static int udp_lua_setsockname(lua_State * L) |
| 256 | { | 256 | { |
| 257 | p_udp udp = (p_udp) lua_touserdata(L, 1); | 257 | p_udp udp = (p_udp) lua_touserdata(L, 1); |
| 258 | cchar *address = luaL_check_string(L, 2); | 258 | cchar *address = luaL_checkstring(L, 2); |
| 259 | ushort port = (ushort) luaL_check_number(L, 3); | 259 | ushort port = (ushort) luaL_checknumber(L, 3); |
| 260 | cchar *err = inet_trybind((p_inet) udp, address, port); | 260 | cchar *err = inet_trybind((p_inet) udp, address, port); |
| 261 | if (err) lua_pushstring(L, err); | 261 | if (err) lua_pushstring(L, err); |
| 262 | else lua_pushnil(L); | 262 | else lua_pushnil(L); |
| @@ -275,8 +275,8 @@ static int udp_lua_setsockname(lua_State * L) | |||
| 275 | static int udp_lua_setpeername(lua_State *L) | 275 | static int udp_lua_setpeername(lua_State *L) |
| 276 | { | 276 | { |
| 277 | p_udp udp = (p_udp) lua_touserdata(L, 1); | 277 | p_udp udp = (p_udp) lua_touserdata(L, 1); |
| 278 | cchar *address = luaL_check_string(L, 2); | 278 | cchar *address = luaL_checkstring(L, 2); |
| 279 | ushort port = (ushort) luaL_check_number(L, 3); | 279 | ushort port = (ushort) luaL_checknumber(L, 3); |
| 280 | cchar *err = inet_tryconnect((p_inet) udp, address, port); | 280 | cchar *err = inet_tryconnect((p_inet) udp, address, port); |
| 281 | if (!err) { | 281 | if (!err) { |
| 282 | udp->udp_connected = 1; | 282 | udp->udp_connected = 1; |
