From 32fd039bb563b24cbe4621dcc9b3cc18d9e078b0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 20 Dec 2002 08:26:33 -0200 Subject: [PATCH] `openlib' functions return new module --- ldblib.c | 4 ++-- liolib.c | 4 ++-- lmathlib.c | 4 ++-- lstrlib.c | 4 ++-- ltablib.c | 4 ++-- ltests.c | 25 +++++++++++++++++-------- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ldblib.c b/ldblib.c index 98b3106b..bef81bdd 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.75 2002/12/05 17:50:10 roberto Exp roberto $ +** $Id: ldblib.c,v 1.76 2002/12/19 11:11:55 roberto Exp roberto $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -292,6 +292,6 @@ LUALIB_API int lua_dblibopen (lua_State *L) { lua_pushliteral(L, "_TRACEBACK"); lua_pushcfunction(L, errorfb); lua_settable(L, LUA_GLOBALSINDEX); - return 0; + return 1; } diff --git a/liolib.c b/liolib.c index 2d901f93..f61e1823 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.27 2002/12/04 15:27:17 roberto Exp roberto $ +** $Id: liolib.c,v 2.28 2002/12/04 17:38:31 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -732,6 +732,6 @@ LUALIB_API int lua_iolibopen (lua_State *L) { registerfile(L, stdin, "stdin", IO_INPUT); registerfile(L, stdout, "stdout", IO_OUTPUT); registerfile(L, stderr, "stderr", NULL); - return 0; + return 1; } diff --git a/lmathlib.c b/lmathlib.c index ce8b04c3..3a6420c4 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.52 2002/11/14 15:41:38 roberto Exp roberto $ +** $Id: lmathlib.c,v 1.53 2002/12/04 17:38:31 roberto Exp roberto $ ** Standard mathematical library ** See Copyright Notice in lua.h */ @@ -241,6 +241,6 @@ LUALIB_API int lua_mathlibopen (lua_State *L) { lua_pushliteral(L, "__pow"); lua_pushcfunction(L, math_pow); lua_settable(L, LUA_REGISTRYINDEX); - return 0; + return 1; } diff --git a/lstrlib.c b/lstrlib.c index 64f731b8..f4d37620 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.91 2002/11/25 17:33:33 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.92 2002/12/04 17:38:31 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -763,6 +763,6 @@ static const luaL_reg strlib[] = { */ LUALIB_API int lua_strlibopen (lua_State *L) { luaL_openlib(L, LUA_STRLIBNAME, strlib, 0); - return 0; + return 1; } diff --git a/ltablib.c b/ltablib.c index 9ad7d3a0..504081bc 100644 --- a/ltablib.c +++ b/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.16 2002/11/14 15:41:38 roberto Exp roberto $ +** $Id: ltablib.c,v 1.17 2002/12/04 17:38:31 roberto Exp roberto $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -296,6 +296,6 @@ LUALIB_API int lua_tablibopen (lua_State *L) { lua_pushliteral(L, "k"); lua_rawset(L, -3); /* metatable(N).__mode = "k" */ luaL_openlib(L, LUA_TABLIBNAME, tab_funcs, 1); - return 0; + return 1; } diff --git a/ltests.c b/ltests.c index a326c2de..68944cf4 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 1.148 2002/12/04 17:38:31 roberto Exp roberto $ +** $Id: ltests.c,v 1.149 2002/12/19 11:11:55 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -457,13 +457,21 @@ static int newstate (lua_State *L) { return 1; } + static int loadlib (lua_State *L) { - lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1))); - lua_register(L1, "mathlibopen", lua_mathlibopen); - lua_register(L1, "strlibopen", lua_strlibopen); - lua_register(L1, "iolibopen", lua_iolibopen); - lua_register(L1, "dblibopen", lua_dblibopen); - lua_register(L1, "baselibopen", lua_baselibopen); + static const luaL_reg libs[] = { + {"mathlibopen", lua_mathlibopen}, + {"strlibopen", lua_strlibopen}, + {"iolibopen", lua_iolibopen}, + {"tablibopen", lua_tablibopen}, + {"dblibopen", lua_dblibopen}, + {"baselibopen", lua_baselibopen}, + {NULL, NULL} + }; + lua_State *L1 = cast(lua_State *, + cast(unsigned long, luaL_checknumber(L, 1))); + lua_pushvalue(L1, LUA_GLOBALSINDEX); + luaL_openlib(L1, NULL, libs, 0); return 0; } @@ -486,7 +494,8 @@ static int doremote (lua_State *L) { if (status != 0) { lua_pushnil(L); lua_pushnumber(L, status); - return 2; + lua_pushstring(L, lua_tostring(L1, -1)); + return 3; } else { int i = 0;