2000-06-02 19:55:14 +02:00
|
|
|
/*=========================================================================*\
|
2003-06-26 20:47:49 +02:00
|
|
|
* LuaSocket toolkit
|
2002-07-03 21:06:52 +02:00
|
|
|
* Networking support for the Lua language
|
2000-06-02 19:55:14 +02:00
|
|
|
* Diego Nehab
|
|
|
|
* 26/11/1999
|
|
|
|
*
|
2002-07-03 21:06:52 +02:00
|
|
|
* This library is part of an effort to progressively increase the network
|
|
|
|
* connectivity of the Lua language. The Lua interface to networking
|
|
|
|
* functions follows the Sockets API closely, trying to simplify all tasks
|
|
|
|
* involved in setting up both client and server connections. The provided
|
2003-06-26 20:47:49 +02:00
|
|
|
* IO routines, however, follow the Lua style, being very similar to the
|
2002-07-03 21:06:52 +02:00
|
|
|
* standard Lua read and write functions.
|
2001-09-13 00:07:08 +02:00
|
|
|
*
|
|
|
|
* RCS ID: $Id$
|
2000-06-02 19:55:14 +02:00
|
|
|
\*=========================================================================*/
|
|
|
|
|
|
|
|
/*=========================================================================*\
|
2002-07-03 21:06:52 +02:00
|
|
|
* Standard include files
|
2000-06-02 19:55:14 +02:00
|
|
|
\*=========================================================================*/
|
2001-01-13 08:10:00 +01:00
|
|
|
#include <lua.h>
|
2002-07-03 21:06:52 +02:00
|
|
|
#include <lauxlib.h>
|
2001-01-13 08:10:00 +01:00
|
|
|
|
2001-01-15 05:16:35 +01:00
|
|
|
/*=========================================================================*\
|
2002-07-03 21:06:52 +02:00
|
|
|
* LuaSocket includes
|
2001-01-15 05:16:35 +01:00
|
|
|
\*=========================================================================*/
|
2002-07-03 21:06:52 +02:00
|
|
|
#include "luasocket.h"
|
2003-05-25 03:54:13 +02:00
|
|
|
|
2004-05-25 07:27:44 +02:00
|
|
|
#include "base.h"
|
2003-06-26 20:47:49 +02:00
|
|
|
#include "auxiliar.h"
|
2003-06-09 20:23:40 +02:00
|
|
|
#include "timeout.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "socket.h"
|
2003-05-25 03:54:13 +02:00
|
|
|
#include "inet.h"
|
|
|
|
#include "tcp.h"
|
|
|
|
#include "udp.h"
|
2003-06-09 20:23:40 +02:00
|
|
|
#include "select.h"
|
2004-02-04 15:29:11 +01:00
|
|
|
#include "smtp.h"
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*\
|
|
|
|
* Modules
|
|
|
|
\*-------------------------------------------------------------------------*/
|
|
|
|
static const luaL_reg mod[] = {
|
|
|
|
{"base", base_open},
|
|
|
|
{"aux", aux_open},
|
|
|
|
{"tm", tm_open},
|
|
|
|
{"buf", buf_open},
|
|
|
|
{"inet", inet_open},
|
|
|
|
{"tcp", tcp_open},
|
|
|
|
{"udp", udp_open},
|
|
|
|
{"select", select_open},
|
|
|
|
{"smtp", smtp_open},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*\
|
|
|
|
* Initializes all library modules.
|
|
|
|
\*-------------------------------------------------------------------------*/
|
|
|
|
LUASOCKET_API int luaopen_socket(lua_State *L)
|
|
|
|
{
|
2004-05-28 08:16:43 +02:00
|
|
|
int i;
|
2004-02-04 15:29:11 +01:00
|
|
|
if (!sock_open()) {
|
|
|
|
lua_pushnil(L);
|
|
|
|
lua_pushstring(L, "unable to initialize library");
|
|
|
|
return 2;
|
|
|
|
}
|
2004-05-28 08:16:43 +02:00
|
|
|
for (i = 0; mod[i].name; i++)
|
|
|
|
mod[i].func(L);
|
2003-06-09 20:23:40 +02:00
|
|
|
return 1;
|
2001-01-15 05:16:35 +01:00
|
|
|
}
|