diff options
| -rw-r--r-- | lbaselib.c | 51 |
1 files changed, 41 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.2 2000/09/12 13:49:05 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.3 2000/09/12 18:41:43 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 | */ |
| @@ -534,31 +534,62 @@ static int luaB_sort (lua_State *L) { | |||
| 534 | */ | 534 | */ |
| 535 | 535 | ||
| 536 | 536 | ||
| 537 | #define num_deprecated 4 | ||
| 538 | |||
| 539 | static const struct luaL_reg deprecated_names [num_deprecated] = { | ||
| 540 | {"foreachvar", luaB_foreach}, | ||
| 541 | {"nextvar", luaB_next}, | ||
| 542 | {"rawgetglobal", luaB_rawget}, | ||
| 543 | {"rawsetglobal", luaB_rawset} | ||
| 544 | }; | ||
| 545 | |||
| 546 | |||
| 547 | #ifdef LUA_DEPRECATETFUNCS | ||
| 548 | |||
| 537 | /* | 549 | /* |
| 538 | ** gives an explicit error in any attempt to call a deprecated function | 550 | ** call corresponding function inserting `globals' as first argument |
| 539 | */ | 551 | */ |
| 540 | static int deprecated_func (lua_State *L) { | 552 | static int deprecated_func (lua_State *L) { |
| 541 | luaL_verror(L, "function `%.20s' is deprecated", luaL_check_string(L, -1)); | 553 | lua_insert(L, 1); /* upvalue is the function to be called */ |
| 542 | return 0; /* to avoid warnings */ | 554 | lua_getglobals(L); |
| 555 | lua_insert(L, 2); /* table of globals is 1o argument */ | ||
| 556 | if (lua_call(L, lua_gettop(L)-1, LUA_MULTRET) != 0) | ||
| 557 | lua_error(L, NULL); | ||
| 558 | return lua_gettop(L); /* return all results */ | ||
| 543 | } | 559 | } |
| 544 | 560 | ||
| 545 | 561 | ||
| 546 | #define num_deprecated 4 | 562 | static void deprecated_funcs (lua_State *L) { |
| 563 | int i; | ||
| 564 | for (i=0; i<num_deprecated; i++) { | ||
| 565 | lua_pushcfunction(L, deprecated_names[i].func); | ||
| 566 | lua_pushcclosure(L, deprecated_func, 1); | ||
| 567 | lua_setglobal(L, deprecated_names[i].name); | ||
| 568 | } | ||
| 569 | } | ||
| 547 | 570 | ||
| 548 | static const char *const deprecated_names [num_deprecated] = { | 571 | |
| 549 | "foreachvar", "nextvar", "rawgetglobal", "rawsetglobal" | 572 | #else |
| 550 | }; | 573 | |
| 574 | /* | ||
| 575 | ** gives an explicit error in any attempt to call a deprecated function | ||
| 576 | */ | ||
| 577 | static int deprecated_func (lua_State *L) { | ||
| 578 | luaL_verror(L, "function `%.20s' is deprecated", lua_tostring(L, -1)); | ||
| 579 | return 0; /* to avoid warnings */ | ||
| 580 | } | ||
| 551 | 581 | ||
| 552 | 582 | ||
| 553 | static void deprecated_funcs (lua_State *L) { | 583 | static void deprecated_funcs (lua_State *L) { |
| 554 | int i; | 584 | int i; |
| 555 | for (i=0; i<num_deprecated; i++) { | 585 | for (i=0; i<num_deprecated; i++) { |
| 556 | lua_pushstring(L, deprecated_names[i]); | 586 | lua_pushstring(L, deprecated_names[i].name); |
| 557 | lua_pushcclosure(L, deprecated_func, 1); | 587 | lua_pushcclosure(L, deprecated_func, 1); |
| 558 | lua_setglobal(L, deprecated_names[i]); | 588 | lua_setglobal(L, deprecated_names[i].name); |
| 559 | } | 589 | } |
| 560 | } | 590 | } |
| 561 | 591 | ||
| 592 | #endif | ||
| 562 | 593 | ||
| 563 | /* }====================================================== */ | 594 | /* }====================================================== */ |
| 564 | 595 | ||
