diff options
-rw-r--r-- | lbaselib.c | 24 | ||||
-rw-r--r-- | ldblib.c | 5 | ||||
-rw-r--r-- | liolib.c | 5 | ||||
-rw-r--r-- | lmathlib.c | 5 | ||||
-rw-r--r-- | lstrlib.c | 5 | ||||
-rw-r--r-- | ltests.c | 18 | ||||
-rw-r--r-- | lualib.h | 12 |
7 files changed, 42 insertions, 32 deletions
@@ -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 | ||
299 | static 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 | |||
299 | static int luaB_call (lua_State *L) { | 310 | static 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 | ||
679 | LUALIB_API void lua_baselibopen (lua_State *L) { | 686 | LUALIB_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 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.32 2001/02/02 19:02:40 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.33 2001/02/23 17:17:25 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -182,7 +182,8 @@ static const luaL_reg dblib[] = { | |||
182 | }; | 182 | }; |
183 | 183 | ||
184 | 184 | ||
185 | LUALIB_API void lua_dblibopen (lua_State *L) { | 185 | LUALIB_API int lua_dblibopen (lua_State *L) { |
186 | luaL_openl(L, dblib); | 186 | luaL_openl(L, dblib); |
187 | return 0; | ||
187 | } | 188 | } |
188 | 189 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.108 2001/02/23 17:17:25 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.109 2001/02/23 17:28:12 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -675,7 +675,7 @@ static const luaL_reg iolib[] = { | |||
675 | }; | 675 | }; |
676 | 676 | ||
677 | 677 | ||
678 | LUALIB_API void lua_iolibopen (lua_State *L) { | 678 | LUALIB_API int lua_iolibopen (lua_State *L) { |
679 | int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA); | 679 | int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA); |
680 | lua_newtype(L, l_s("ClosedFileHandle"), LUA_TUSERDATA); | 680 | lua_newtype(L, l_s("ClosedFileHandle"), LUA_TUSERDATA); |
681 | luaL_openl(L, iolib); | 681 | luaL_openl(L, iolib); |
@@ -688,5 +688,6 @@ LUALIB_API void lua_iolibopen (lua_State *L) { | |||
688 | /* close files when collected */ | 688 | /* close files when collected */ |
689 | lua_pushcfunction(L, file_collect); | 689 | lua_pushcfunction(L, file_collect); |
690 | lua_settagmethod(L, iotag, l_s("gc")); | 690 | lua_settagmethod(L, iotag, l_s("gc")); |
691 | return 0; | ||
691 | } | 692 | } |
692 | 693 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.35 2001/02/22 18:59:59 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.36 2001/02/23 17:17:25 roberto Exp roberto $ |
3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -228,11 +228,12 @@ static const luaL_reg mathlib[] = { | |||
228 | /* | 228 | /* |
229 | ** Open math library | 229 | ** Open math library |
230 | */ | 230 | */ |
231 | LUALIB_API void lua_mathlibopen (lua_State *L) { | 231 | LUALIB_API int lua_mathlibopen (lua_State *L) { |
232 | luaL_openl(L, mathlib); | 232 | luaL_openl(L, mathlib); |
233 | lua_pushcfunction(L, math_pow); | 233 | lua_pushcfunction(L, math_pow); |
234 | lua_settagmethod(L, LUA_TNUMBER, l_s("pow")); | 234 | lua_settagmethod(L, LUA_TNUMBER, l_s("pow")); |
235 | lua_pushnumber(L, PI); | 235 | lua_pushnumber(L, PI); |
236 | lua_setglobal(L, l_s("PI")); | 236 | lua_setglobal(L, l_s("PI")); |
237 | return 0; | ||
237 | } | 238 | } |
238 | 239 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.65 2001/02/23 17:17:25 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.66 2001/03/02 17:40:08 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -652,6 +652,7 @@ static const luaL_reg strlib[] = { | |||
652 | /* | 652 | /* |
653 | ** Open string library | 653 | ** Open string library |
654 | */ | 654 | */ |
655 | LUALIB_API void lua_strlibopen (lua_State *L) { | 655 | LUALIB_API int lua_strlibopen (lua_State *L) { |
656 | luaL_openl(L, strlib); | 656 | luaL_openl(L, strlib); |
657 | return 0; | ||
657 | } | 658 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.72 2001/02/23 17:17:25 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.73 2001/03/02 17:27:50 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -417,15 +417,12 @@ static int newstate (lua_State *L) { | |||
417 | } | 417 | } |
418 | 418 | ||
419 | static int loadlib (lua_State *L) { | 419 | static int loadlib (lua_State *L) { |
420 | lua_State *L1 = (lua_State *)lua_touserdata(L, 1); | 420 | lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); |
421 | switch (*luaL_check_string(L, 2)) { | 421 | lua_register(L1, "mathlibopen", lua_mathlibopen); |
422 | case l_c('m'): lua_mathlibopen(L1); break; | 422 | lua_register(L1, "strlibopen", lua_strlibopen); |
423 | case l_c('s'): lua_strlibopen(L1); break; | 423 | lua_register(L1, "iolibopen", lua_iolibopen); |
424 | case l_c('i'): lua_iolibopen(L1); break; | 424 | lua_register(L1, "dblibopen", lua_dblibopen); |
425 | case l_c('d'): lua_dblibopen(L1); break; | 425 | lua_register(L1, "baselibopen", lua_baselibopen); |
426 | case l_c('b'): lua_baselibopen(L1); break; | ||
427 | default: luaL_argerror(L, 2, l_s("invalid option")); | ||
428 | } | ||
429 | return 0; | 426 | return 0; |
430 | } | 427 | } |
431 | 428 | ||
@@ -451,6 +448,7 @@ static int doremote (lua_State *L) { | |||
451 | int i = 0; | 448 | int i = 0; |
452 | while (!lua_isnull(L1, ++i)) | 449 | while (!lua_isnull(L1, ++i)) |
453 | lua_pushstring(L, lua_tostring(L1, i)); | 450 | lua_pushstring(L, lua_tostring(L1, i)); |
451 | lua_pop(L1, i-1); | ||
454 | return i-1; | 452 | return i-1; |
455 | } | 453 | } |
456 | } | 454 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lualib.h,v 1.18 2001/02/23 17:28:12 roberto Exp roberto $ | 2 | ** $Id: lualib.h,v 1.19 2001/02/23 20:31:37 roberto Exp roberto $ |
3 | ** Lua standard libraries | 3 | ** Lua standard libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -18,11 +18,11 @@ | |||
18 | 18 | ||
19 | #define LUA_ALERT l_s("_ALERT") | 19 | #define LUA_ALERT l_s("_ALERT") |
20 | 20 | ||
21 | LUALIB_API void lua_baselibopen (lua_State *L); | 21 | LUALIB_API int lua_baselibopen (lua_State *L); |
22 | LUALIB_API void lua_iolibopen (lua_State *L); | 22 | LUALIB_API int lua_iolibopen (lua_State *L); |
23 | LUALIB_API void lua_strlibopen (lua_State *L); | 23 | LUALIB_API int lua_strlibopen (lua_State *L); |
24 | LUALIB_API void lua_mathlibopen (lua_State *L); | 24 | LUALIB_API int lua_mathlibopen (lua_State *L); |
25 | LUALIB_API void lua_dblibopen (lua_State *L); | 25 | LUALIB_API int lua_dblibopen (lua_State *L); |
26 | 26 | ||
27 | 27 | ||
28 | 28 | ||