diff options
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.133 2003/08/27 21:02:08 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.134 2003/10/07 20:13:41 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 | */ |
@@ -220,8 +220,7 @@ static int luaB_next (lua_State *L) { | |||
220 | 220 | ||
221 | static int luaB_pairs (lua_State *L) { | 221 | static int luaB_pairs (lua_State *L) { |
222 | luaL_checktype(L, 1, LUA_TTABLE); | 222 | luaL_checktype(L, 1, LUA_TTABLE); |
223 | lua_pushliteral(L, "next"); | 223 | lua_getfield(L, LUA_GLOBALSINDEX, "next"); /* return generator, */ |
224 | lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */ | ||
225 | lua_pushvalue(L, 1); /* state, */ | 224 | lua_pushvalue(L, 1); /* state, */ |
226 | lua_pushnil(L); /* and initial value */ | 225 | lua_pushnil(L); /* and initial value */ |
227 | return 3; | 226 | return 3; |
@@ -232,8 +231,7 @@ static int luaB_ipairs (lua_State *L) { | |||
232 | int i = (int)lua_tointeger(L, 2); | 231 | int i = (int)lua_tointeger(L, 2); |
233 | luaL_checktype(L, 1, LUA_TTABLE); | 232 | luaL_checktype(L, 1, LUA_TTABLE); |
234 | if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ | 233 | if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ |
235 | lua_pushliteral(L, "ipairs"); | 234 | lua_getfield(L, LUA_GLOBALSINDEX, "ipairs"); /* return generator, */ |
236 | lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */ | ||
237 | lua_pushvalue(L, 1); /* state, */ | 235 | lua_pushvalue(L, 1); /* state, */ |
238 | lua_pushinteger(L, 0); /* and initial value */ | 236 | lua_pushinteger(L, 0); /* and initial value */ |
239 | return 3; | 237 | return 3; |
@@ -693,23 +691,19 @@ static const luaL_reg co_funcs[] = { | |||
693 | 691 | ||
694 | 692 | ||
695 | static void base_open (lua_State *L) { | 693 | static void base_open (lua_State *L) { |
696 | lua_pushliteral(L, "_G"); | ||
697 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 694 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
698 | luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */ | 695 | luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */ |
699 | lua_pushliteral(L, "_VERSION"); | ||
700 | lua_pushliteral(L, LUA_VERSION); | 696 | lua_pushliteral(L, LUA_VERSION); |
701 | lua_rawset(L, -3); /* set global _VERSION */ | 697 | lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */ |
702 | /* `newproxy' needs a weaktable as upvalue */ | 698 | /* `newproxy' needs a weaktable as upvalue */ |
703 | lua_pushliteral(L, "newproxy"); | ||
704 | lua_newtable(L); /* new table `w' */ | 699 | lua_newtable(L); /* new table `w' */ |
705 | lua_pushvalue(L, -1); /* `w' will be its own metatable */ | 700 | lua_pushvalue(L, -1); /* `w' will be its own metatable */ |
706 | lua_setmetatable(L, -2); | 701 | lua_setmetatable(L, -2); |
707 | lua_pushliteral(L, "__mode"); | ||
708 | lua_pushliteral(L, "kv"); | 702 | lua_pushliteral(L, "kv"); |
709 | lua_rawset(L, -3); /* metatable(w).__mode = "kv" */ | 703 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ |
710 | lua_pushcclosure(L, luaB_newproxy, 1); | 704 | lua_pushcclosure(L, luaB_newproxy, 1); |
711 | lua_rawset(L, -3); /* set global `newproxy' */ | 705 | lua_setfield(L, -2, "newproxy"); /* set global `newproxy' */ |
712 | lua_rawset(L, -1); /* set global _G */ | 706 | lua_setfield(L, -1, "_G"); /* set global _G */ |
713 | } | 707 | } |
714 | 708 | ||
715 | 709 | ||