aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-12-04 13:38:25 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-12-04 13:38:25 -0200
commit76de732745d5781fe3ee1af4fd43f01a6c4b8ce4 (patch)
treea0f557ac472507dbcfea7ca50d39ad5e1194af01 /lbaselib.c
parent90d7892007e399765cf8d14f65f7e3bc4a96e087 (diff)
downloadlua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.tar.gz
lua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.tar.bz2
lua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.zip
avoid non-raw accesses to globals when variable may not exist
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 6025addc..2c233569 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.111 2002/11/26 08:45:36 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.112 2002/11/26 12:53:29 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*/
@@ -213,7 +213,8 @@ static int luaB_next (lua_State *L) {
213 213
214static int luaB_pairs (lua_State *L) { 214static int luaB_pairs (lua_State *L) {
215 luaL_checktype(L, 1, LUA_TTABLE); 215 luaL_checktype(L, 1, LUA_TTABLE);
216 lua_getglobal(L, "next"); /* return generator, */ 216 lua_pushliteral(L, "next");
217 lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */
217 lua_pushvalue(L, 1); /* state, */ 218 lua_pushvalue(L, 1); /* state, */
218 lua_pushnil(L); /* and initial value */ 219 lua_pushnil(L); /* and initial value */
219 return 3; 220 return 3;
@@ -224,7 +225,8 @@ static int luaB_ipairs (lua_State *L) {
224 lua_Number i = lua_tonumber(L, 2); 225 lua_Number i = lua_tonumber(L, 2);
225 luaL_checktype(L, 1, LUA_TTABLE); 226 luaL_checktype(L, 1, LUA_TTABLE);
226 if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ 227 if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */
227 lua_getglobal(L, "ipairs"); /* return generator, */ 228 lua_pushliteral(L, "ipairs");
229 lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */
228 lua_pushvalue(L, 1); /* state, */ 230 lua_pushvalue(L, 1); /* state, */
229 lua_pushnumber(L, 0); /* and initial value */ 231 lua_pushnumber(L, 0); /* and initial value */
230 return 3; 232 return 3;