Working on the manual...

Making better tests for error messages.
Changed a few names.
Moved gethostname to inet.c.
This commit is contained in:
Diego Nehab 2004-01-24 02:47:24 +00:00
parent 0c9f420a35
commit 62a4c505e4
21 changed files with 341 additions and 315 deletions

View file

@ -38,15 +38,8 @@
/*=========================================================================*\
* Declarations
\*=========================================================================*/
static int global_gethostname(lua_State *L);
static int base_open(lua_State *L);
/* functions in library namespace */
static luaL_reg func[] = {
{"gethostname", global_gethostname},
{NULL, NULL}
};
/*-------------------------------------------------------------------------*\
* Setup basic stuff.
\*-------------------------------------------------------------------------*/
@ -70,29 +63,9 @@ static int base_open(lua_State *L)
lua_pushstring(L, "LUASOCKET_LIBNAME");
lua_pushstring(L, LUASOCKET_LIBNAME);
lua_settable(L, LUA_GLOBALSINDEX);
/* define library functions */
luaL_openlib(L, LUASOCKET_LIBNAME, func, 0);
lua_pop(L, 1);
return 0;
}
/*-------------------------------------------------------------------------*\
* Gets the host name
\*-------------------------------------------------------------------------*/
static int global_gethostname(lua_State *L)
{
char name[257];
name[256] = '\0';
if (gethostname(name, 256) < 0) {
lua_pushnil(L);
lua_pushstring(L, "gethostname failed");
return 2;
} else {
lua_pushstring(L, name);
return 1;
}
}
/*-------------------------------------------------------------------------*\
* Initializes all library modules.
\*-------------------------------------------------------------------------*/