diff options
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 25 |
1 files changed, 19 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.92 2002/08/05 14:46:02 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.93 2002/08/06 15:32:22 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 | */ |
| @@ -81,6 +81,21 @@ static int luaB_error (lua_State *L) { | |||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | 83 | ||
| 84 | static int luaB_getmode (lua_State *L) { | ||
| 85 | luaL_check_type(L, 1, LUA_TTABLE); | ||
| 86 | lua_pushstring(L, lua_getmode(L, 1)); | ||
| 87 | return 1; | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | static int luaB_setmode (lua_State *L) { | ||
| 92 | luaL_check_type(L, 1, LUA_TTABLE); | ||
| 93 | lua_setmode(L, 1, luaL_check_string(L, 2)); | ||
| 94 | lua_settop(L, 1); | ||
| 95 | return 1; | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 84 | static int luaB_getmetatable (lua_State *L) { | 99 | static int luaB_getmetatable (lua_State *L) { |
| 85 | luaL_check_any(L, 1); | 100 | luaL_check_any(L, 1); |
| 86 | if (!lua_getmetatable(L, 1)) { | 101 | if (!lua_getmetatable(L, 1)) { |
| @@ -460,6 +475,8 @@ static const luaL_reg base_funcs[] = { | |||
| 460 | {"setmetatable", luaB_setmetatable}, | 475 | {"setmetatable", luaB_setmetatable}, |
| 461 | {"getglobals", luaB_getglobals}, | 476 | {"getglobals", luaB_getglobals}, |
| 462 | {"setglobals", luaB_setglobals}, | 477 | {"setglobals", luaB_setglobals}, |
| 478 | {"getmode", luaB_getmode}, | ||
| 479 | {"setmode", luaB_setmode}, | ||
| 463 | {"next", luaB_next}, | 480 | {"next", luaB_next}, |
| 464 | {"ipairs", luaB_ipairs}, | 481 | {"ipairs", luaB_ipairs}, |
| 465 | {"pairs", luaB_pairs}, | 482 | {"pairs", luaB_pairs}, |
| @@ -572,11 +589,7 @@ static void base_open (lua_State *L) { | |||
| 572 | /* `newproxy' needs a weaktable as upvalue */ | 589 | /* `newproxy' needs a weaktable as upvalue */ |
| 573 | lua_pushliteral(L, "newproxy"); | 590 | lua_pushliteral(L, "newproxy"); |
| 574 | lua_newtable(L); /* new table `w' */ | 591 | lua_newtable(L); /* new table `w' */ |
| 575 | lua_pushvalue(L, -1); /* `w' will be its own metatable */ | 592 | lua_setmode(L, -1, "k"); |
| 576 | lua_setmetatable(L, -2); | ||
| 577 | lua_pushliteral(L, "__mode"); | ||
| 578 | lua_pushliteral(L, "k"); | ||
| 579 | lua_rawset(L, -3); /* metatable(w).__mode = "k" */ | ||
| 580 | lua_pushcclosure(L, luaB_newproxy, 1); | 593 | lua_pushcclosure(L, luaB_newproxy, 1); |
| 581 | lua_rawset(L, -3); /* set global `newproxy' */ | 594 | lua_rawset(L, -3); /* set global `newproxy' */ |
| 582 | lua_rawset(L, -1); /* set global _G */ | 595 | lua_rawset(L, -1); /* set global _G */ |
