commit 32fd039bb563b24cbe4621dcc9b3cc18d9e078b0
parent 75f73172c463af9643bc187eed7f1fd195238078
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 20 Dec 2002 08:26:11 -0200
`openlib' functions return new module
Diffstat:
6 files changed, 27 insertions(+), 18 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;