commit 6d4db86888ea8ef06b78646f2631891c9e4c7a2b
parent e9a38203700865d36c3b2861200674a21930c1b5
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 6 Mar 2001 17:09:16 -0300
open functions are lua_Cfunctions
Diffstat:
7 files changed, 42 insertions(+), 32 deletions(-)
diff --git a/lbaselib.c b/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.27 2001/02/23 17:17:25 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.28 2001/02/23 17:28:12 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -296,14 +296,23 @@ static int luaB_dofile (lua_State *L) {
}
+static int aux_unpack (lua_State *L, int arg) {
+ int n, i;
+ luaL_checktype(L, arg, LUA_TTABLE);
+ n = lua_getn(L, arg);
+ luaL_checkstack(L, n, l_s("too many arguments"));
+ for (i=1; i<=n; i++) /* push arg[1...n] */
+ lua_rawgeti(L, arg, i);
+ return n;
+}
+
+
static int luaB_call (lua_State *L) {
int oldtop;
const l_char *options = luaL_opt_string(L, 3, l_s(""));
int err = 0; /* index of old error method */
- int i, status;
+ int status;
int n;
- luaL_checktype(L, 2, LUA_TTABLE);
- n = lua_getn(L, 2);
if (!lua_isnull(L, 4)) { /* set new error method */
lua_getglobal(L, LUA_ERRORMESSAGE);
err = lua_gettop(L); /* get index */
@@ -313,9 +322,7 @@ static int luaB_call (lua_State *L) {
oldtop = lua_gettop(L); /* top before function-call preparation */
/* push function */
lua_pushvalue(L, 1);
- luaL_checkstack(L, n, l_s("too many arguments"));
- for (i=0; i<n; i++) /* push arg[1...n] */
- lua_rawgeti(L, 2, i+1);
+ n = aux_unpack(L, 2); /* push arg[1...n] */
status = lua_call(L, n, LUA_MULTRET);
if (err != 0) { /* restore old error method */
lua_pushvalue(L, err);
@@ -676,10 +683,11 @@ static const luaL_reg base_funcs[] = {
-LUALIB_API void lua_baselibopen (lua_State *L) {
+LUALIB_API int lua_baselibopen (lua_State *L) {
luaL_openl(L, base_funcs);
lua_pushliteral(L, LUA_VERSION);
lua_setglobal(L, l_s("_VERSION"));
deprecated_funcs(L);
+ return 0;
}
diff --git a/ldblib.c b/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.32 2001/02/02 19:02:40 roberto Exp roberto $
+** $Id: ldblib.c,v 1.33 2001/02/23 17:17:25 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -182,7 +182,8 @@ static const luaL_reg dblib[] = {
};
-LUALIB_API void lua_dblibopen (lua_State *L) {
+LUALIB_API int lua_dblibopen (lua_State *L) {
luaL_openl(L, dblib);
+ return 0;
}
diff --git a/liolib.c b/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 1.108 2001/02/23 17:17:25 roberto Exp roberto $
+** $Id: liolib.c,v 1.109 2001/02/23 17:28:12 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -675,7 +675,7 @@ static const luaL_reg iolib[] = {
};
-LUALIB_API void lua_iolibopen (lua_State *L) {
+LUALIB_API int lua_iolibopen (lua_State *L) {
int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA);
lua_newtype(L, l_s("ClosedFileHandle"), LUA_TUSERDATA);
luaL_openl(L, iolib);
@@ -688,5 +688,6 @@ LUALIB_API void lua_iolibopen (lua_State *L) {
/* close files when collected */
lua_pushcfunction(L, file_collect);
lua_settagmethod(L, iotag, l_s("gc"));
+ return 0;
}
diff --git a/lmathlib.c b/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.35 2001/02/22 18:59:59 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.36 2001/02/23 17:17:25 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -228,11 +228,12 @@ static const luaL_reg mathlib[] = {
/*
** Open math library
*/
-LUALIB_API void lua_mathlibopen (lua_State *L) {
+LUALIB_API int lua_mathlibopen (lua_State *L) {
luaL_openl(L, mathlib);
lua_pushcfunction(L, math_pow);
lua_settagmethod(L, LUA_TNUMBER, l_s("pow"));
lua_pushnumber(L, PI);
lua_setglobal(L, l_s("PI"));
+ return 0;
}
diff --git a/lstrlib.c b/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.65 2001/02/23 17:17:25 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.66 2001/03/02 17:40:08 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -652,6 +652,7 @@ static const luaL_reg strlib[] = {
/*
** Open string library
*/
-LUALIB_API void lua_strlibopen (lua_State *L) {
+LUALIB_API int lua_strlibopen (lua_State *L) {
luaL_openl(L, strlib);
+ return 0;
}
diff --git a/ltests.c b/ltests.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltests.c,v 1.72 2001/02/23 17:17:25 roberto Exp roberto $
+** $Id: ltests.c,v 1.73 2001/03/02 17:27:50 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@@ -417,15 +417,12 @@ static int newstate (lua_State *L) {
}
static int loadlib (lua_State *L) {
- lua_State *L1 = (lua_State *)lua_touserdata(L, 1);
- switch (*luaL_check_string(L, 2)) {
- case l_c('m'): lua_mathlibopen(L1); break;
- case l_c('s'): lua_strlibopen(L1); break;
- case l_c('i'): lua_iolibopen(L1); break;
- case l_c('d'): lua_dblibopen(L1); break;
- case l_c('b'): lua_baselibopen(L1); break;
- default: luaL_argerror(L, 2, l_s("invalid option"));
- }
+ lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(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);
return 0;
}
@@ -451,6 +448,7 @@ static int doremote (lua_State *L) {
int i = 0;
while (!lua_isnull(L1, ++i))
lua_pushstring(L, lua_tostring(L1, i));
+ lua_pop(L1, i-1);
return i-1;
}
}
diff --git a/lualib.h b/lualib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lualib.h,v 1.18 2001/02/23 17:28:12 roberto Exp roberto $
+** $Id: lualib.h,v 1.19 2001/02/23 20:31:37 roberto Exp roberto $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
@@ -18,11 +18,11 @@
#define LUA_ALERT l_s("_ALERT")
-LUALIB_API void lua_baselibopen (lua_State *L);
-LUALIB_API void lua_iolibopen (lua_State *L);
-LUALIB_API void lua_strlibopen (lua_State *L);
-LUALIB_API void lua_mathlibopen (lua_State *L);
-LUALIB_API void lua_dblibopen (lua_State *L);
+LUALIB_API int lua_baselibopen (lua_State *L);
+LUALIB_API int lua_iolibopen (lua_State *L);
+LUALIB_API int lua_strlibopen (lua_State *L);
+LUALIB_API int lua_mathlibopen (lua_State *L);
+LUALIB_API int lua_dblibopen (lua_State *L);