lua_socketlibopen now returns a result code.

This commit is contained in:
Diego Nehab 2001-09-12 22:07:08 +00:00
parent b2df4282a3
commit d794e581ff

View File

@ -8,12 +8,14 @@
* This module is part of an effort to make the most important features * This module is part of an effort to make the most important features
* of the IPv4 Socket layer available to Lua scripts. * of the IPv4 Socket layer available to Lua scripts.
* The Lua interface to TCP/IP follows the BSD TCP/IP API closely, * The Lua interface to TCP/IP follows the BSD TCP/IP API closely,
* trying to simplify all tasks involved in setting up a client connection * trying to simplify all tasks involved in setting up both client
* and server connections. * and server connections.
* The provided IO routines, send and receive, follow the Lua style, being * The provided IO routines, send and receive, follow the Lua style, being
* very similar to the standard Lua read and write functions. * very similar to the standard Lua read and write functions.
* The module implements both a BSD bind and a Winsock2 bind, and has * The module implements both a BSD bind and a Winsock2 bind, and has
* been tested on several Unix flavors, as well as Windows 98 and NT. * been tested on several Unix flavors, as well as Windows 98 and NT.
*
* RCS ID: $Id$
\*=========================================================================*/ \*=========================================================================*/
/*=========================================================================*\ /*=========================================================================*\
@ -1660,7 +1662,7 @@ static int receive_word(lua_State *L, p_sock sock)
* Initializes the library interface with Lua and the socket library. * Initializes the library interface with Lua and the socket library.
* Defines the symbols exported to Lua. * Defines the symbols exported to Lua.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_API void lua_socketlibopen(lua_State *L) LUASOCKET_API int lua_socketlibopen(lua_State *L)
{ {
struct luaL_reg funcs[] = { struct luaL_reg funcs[] = {
{"bind", global_tcpbind}, {"bind", global_tcpbind},
@ -1674,6 +1676,8 @@ LUASOCKET_API void lua_socketlibopen(lua_State *L)
/* declare new Lua tags for used userdata values */ /* declare new Lua tags for used userdata values */
p_tags tags = (p_tags) lua_newuserdata(L, sizeof(t_tags)); p_tags tags = (p_tags) lua_newuserdata(L, sizeof(t_tags));
if (!tags) lua_error(L, "out of memory"); if (!tags) lua_error(L, "out of memory");
/* remove tags userdatum from stack but avoid garbage collection */
lua_ref(L, 1);
tags->client = lua_newtag(L); tags->client = lua_newtag(L);
tags->server = lua_newtag(L); tags->server = lua_newtag(L);
tags->table = lua_newtag(L); tags->table = lua_newtag(L);
@ -1690,7 +1694,7 @@ LUASOCKET_API void lua_socketlibopen(lua_State *L)
lua_settagmethod(L, tags->table, "gc"); lua_settagmethod(L, tags->table, "gc");
#ifdef WIN32 #ifdef WIN32
/* WinSock needs special initialization */ /* WinSock needs special initialization */
winsock_open(); if (!winsock_open()) return 0;
#else #else
/* avoid getting killed by a SIGPIPE signal thrown by send */ /* avoid getting killed by a SIGPIPE signal thrown by send */
handle_sigpipe(); handle_sigpipe();
@ -1716,6 +1720,7 @@ LUASOCKET_API void lua_socketlibopen(lua_State *L)
} }
} }
#endif #endif
return 1;
} }
/*=========================================================================*\ /*=========================================================================*\