aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 6b5444bf..dceeadfc 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.27 2001/02/23 17:17:25 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.28 2001/02/23 17:28:12 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -296,14 +296,23 @@ static int luaB_dofile (lua_State *L) {
296} 296}
297 297
298 298
299static int aux_unpack (lua_State *L, int arg) {
300 int n, i;
301 luaL_checktype(L, arg, LUA_TTABLE);
302 n = lua_getn(L, arg);
303 luaL_checkstack(L, n, l_s("too many arguments"));
304 for (i=1; i<=n; i++) /* push arg[1...n] */
305 lua_rawgeti(L, arg, i);
306 return n;
307}
308
309
299static int luaB_call (lua_State *L) { 310static int luaB_call (lua_State *L) {
300 int oldtop; 311 int oldtop;
301 const l_char *options = luaL_opt_string(L, 3, l_s("")); 312 const l_char *options = luaL_opt_string(L, 3, l_s(""));
302 int err = 0; /* index of old error method */ 313 int err = 0; /* index of old error method */
303 int i, status; 314 int status;
304 int n; 315 int n;
305 luaL_checktype(L, 2, LUA_TTABLE);
306 n = lua_getn(L, 2);
307 if (!lua_isnull(L, 4)) { /* set new error method */ 316 if (!lua_isnull(L, 4)) { /* set new error method */
308 lua_getglobal(L, LUA_ERRORMESSAGE); 317 lua_getglobal(L, LUA_ERRORMESSAGE);
309 err = lua_gettop(L); /* get index */ 318 err = lua_gettop(L); /* get index */
@@ -313,9 +322,7 @@ static int luaB_call (lua_State *L) {
313 oldtop = lua_gettop(L); /* top before function-call preparation */ 322 oldtop = lua_gettop(L); /* top before function-call preparation */
314 /* push function */ 323 /* push function */
315 lua_pushvalue(L, 1); 324 lua_pushvalue(L, 1);
316 luaL_checkstack(L, n, l_s("too many arguments")); 325 n = aux_unpack(L, 2); /* push arg[1...n] */
317 for (i=0; i<n; i++) /* push arg[1...n] */
318 lua_rawgeti(L, 2, i+1);
319 status = lua_call(L, n, LUA_MULTRET); 326 status = lua_call(L, n, LUA_MULTRET);
320 if (err != 0) { /* restore old error method */ 327 if (err != 0) { /* restore old error method */
321 lua_pushvalue(L, err); 328 lua_pushvalue(L, err);
@@ -676,10 +683,11 @@ static const luaL_reg base_funcs[] = {
676 683
677 684
678 685
679LUALIB_API void lua_baselibopen (lua_State *L) { 686LUALIB_API int lua_baselibopen (lua_State *L) {
680 luaL_openl(L, base_funcs); 687 luaL_openl(L, base_funcs);
681 lua_pushliteral(L, LUA_VERSION); 688 lua_pushliteral(L, LUA_VERSION);
682 lua_setglobal(L, l_s("_VERSION")); 689 lua_setglobal(L, l_s("_VERSION"));
683 deprecated_funcs(L); 690 deprecated_funcs(L);
691 return 0;
684} 692}
685 693