2000-06-02 19:55:14 +02:00
|
|
|
/*=========================================================================*\
|
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
|
|
|
|
* IO routines, however, follow the Lua style, being very similar to the
|
|
|
|
* 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
|
|
|
|
|
|
|
#include "tm.h"
|
|
|
|
#include "buf.h"
|
|
|
|
#include "sock.h"
|
|
|
|
#include "inet.h"
|
|
|
|
#include "tcp.h"
|
|
|
|
#include "udp.h"
|
2000-06-02 19:55:14 +02:00
|
|
|
|
2001-01-15 05:16:35 +01:00
|
|
|
/*=========================================================================*\
|
2002-07-03 21:06:52 +02:00
|
|
|
* Exported functions
|
2001-01-15 05:16:35 +01:00
|
|
|
\*=========================================================================*/
|
2000-06-02 19:55:14 +02:00
|
|
|
/*-------------------------------------------------------------------------*\
|
2002-07-03 21:06:52 +02:00
|
|
|
* Initializes all library modules.
|
2000-06-02 19:55:14 +02:00
|
|
|
\*-------------------------------------------------------------------------*/
|
2003-05-25 03:54:13 +02:00
|
|
|
LUASOCKET_API int luaopen_socketlib(lua_State *L)
|
2000-06-02 19:55:14 +02:00
|
|
|
{
|
2003-05-25 03:54:13 +02:00
|
|
|
/* create namespace table */
|
|
|
|
lua_pushstring(L, LUASOCKET_LIBNAME);
|
|
|
|
lua_newtable(L);
|
|
|
|
#ifdef LUASOCKET_DEBUG
|
|
|
|
lua_pushstring(L, "debug");
|
|
|
|
lua_pushnumber(L, 1);
|
|
|
|
lua_settable(L, -3);
|
|
|
|
#endif
|
|
|
|
lua_settable(L, LUA_GLOBALSINDEX);
|
|
|
|
/* make sure modules know what is our namespace */
|
|
|
|
lua_pushstring(L, "LUASOCKET_LIBNAME");
|
|
|
|
lua_pushstring(L, LUASOCKET_LIBNAME);
|
|
|
|
lua_settable(L, LUA_GLOBALSINDEX);
|
|
|
|
/* initialize all modules */
|
2002-07-03 21:06:52 +02:00
|
|
|
sock_open(L);
|
2003-05-25 03:54:13 +02:00
|
|
|
tm_open(L);
|
2002-07-03 21:06:52 +02:00
|
|
|
buf_open(L);
|
2003-05-25 03:54:13 +02:00
|
|
|
inet_open(L);
|
|
|
|
tcp_open(L);
|
2002-07-03 21:06:52 +02:00
|
|
|
udp_open(L);
|
2003-05-25 03:54:13 +02:00
|
|
|
/* load all Lua code */
|
|
|
|
lua_dofile(L, "luasocket.lua");
|
2002-12-03 00:34:41 +01:00
|
|
|
return 0;
|
2001-01-15 05:16:35 +01:00
|
|
|
}
|