浏览代码

`openlib' functions return new module

Roberto Ierusalimschy 22 年之前
父节点
当前提交
32fd039bb5
共有 6 个文件被更改,包括 27 次插入18 次删除
  1. 2 2
      ldblib.c
  2. 2 2
      liolib.c
  3. 2 2
      lmathlib.c
  4. 2 2
      lstrlib.c
  5. 2 2
      ltablib.c
  6. 17 8
      ltests.c

+ 2 - 2
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
 ** Interface from Lua to its debug API
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -292,6 +292,6 @@ LUALIB_API int lua_dblibopen (lua_State *L) {
   lua_pushliteral(L, "_TRACEBACK");
   lua_pushliteral(L, "_TRACEBACK");
   lua_pushcfunction(L, errorfb);
   lua_pushcfunction(L, errorfb);
   lua_settable(L, LUA_GLOBALSINDEX);
   lua_settable(L, LUA_GLOBALSINDEX);
-  return 0;
+  return 1;
 }
 }
 
 

+ 2 - 2
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
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 ** 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, stdin, "stdin", IO_INPUT);
   registerfile(L, stdout, "stdout", IO_OUTPUT);
   registerfile(L, stdout, "stdout", IO_OUTPUT);
   registerfile(L, stderr, "stderr", NULL);
   registerfile(L, stderr, "stderr", NULL);
-  return 0;
+  return 1;
 }
 }
 
 

+ 2 - 2
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
 ** Standard mathematical library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -241,6 +241,6 @@ LUALIB_API int lua_mathlibopen (lua_State *L) {
   lua_pushliteral(L, "__pow");
   lua_pushliteral(L, "__pow");
   lua_pushcfunction(L, math_pow);
   lua_pushcfunction(L, math_pow);
   lua_settable(L, LUA_REGISTRYINDEX);
   lua_settable(L, LUA_REGISTRYINDEX);
-  return 0;
+  return 1;
 }
 }
 
 

+ 2 - 2
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
 ** Standard library for string operations and pattern-matching
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -763,6 +763,6 @@ static const luaL_reg strlib[] = {
 */
 */
 LUALIB_API int lua_strlibopen (lua_State *L) {
 LUALIB_API int lua_strlibopen (lua_State *L) {
   luaL_openlib(L, LUA_STRLIBNAME, strlib, 0);
   luaL_openlib(L, LUA_STRLIBNAME, strlib, 0);
-  return 0;
+  return 1;
 }
 }
 
 

+ 2 - 2
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
 ** Library for Table Manipulation
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -296,6 +296,6 @@ LUALIB_API int lua_tablibopen (lua_State *L) {
   lua_pushliteral(L, "k");
   lua_pushliteral(L, "k");
   lua_rawset(L, -3);  /* metatable(N).__mode = "k" */
   lua_rawset(L, -3);  /* metatable(N).__mode = "k" */
   luaL_openlib(L, LUA_TABLIBNAME, tab_funcs, 1);
   luaL_openlib(L, LUA_TABLIBNAME, tab_funcs, 1);
-  return 0;
+  return 1;
 }
 }
 
 

+ 17 - 8
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
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -457,13 +457,21 @@ static int newstate (lua_State *L) {
   return 1;
   return 1;
 }
 }
 
 
+
 static int loadlib (lua_State *L) {
 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;
   return 0;
 }
 }
 
 
@@ -486,7 +494,8 @@ static int doremote (lua_State *L) {
   if (status != 0) {
   if (status != 0) {
     lua_pushnil(L);
     lua_pushnil(L);
     lua_pushnumber(L, status);
     lua_pushnumber(L, status);
-    return 2;
+    lua_pushstring(L, lua_tostring(L1, -1));
+    return 3;
   }
   }
   else {
   else {
     int i = 0;
     int i = 0;