aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lbaselib.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 0ceb135c..f7ac6ed1 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.296 2014/08/21 20:07:56 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.297 2014/09/22 06:42:15 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*/
@@ -260,15 +260,8 @@ static int ipairsaux_raw (lua_State *L) {
260*/ 260*/
261static int ipairsaux (lua_State *L) { 261static int ipairsaux (lua_State *L) {
262 int i = luaL_checkint(L, 2) + 1; 262 int i = luaL_checkint(L, 2) + 1;
263 if (i > luaL_len(L, 1)) { /* larger than length? */ 263 lua_pushinteger(L, i);
264 lua_pushnil(L); /* end traversal */ 264 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;
265 return 1;
266 }
267 else {
268 lua_pushinteger(L, i);
269 lua_geti(L, 1, i);
270 return 2;
271 }
272} 265}
273 266
274 267
@@ -278,10 +271,8 @@ static int ipairsaux (lua_State *L) {
278** that can affect the traversal. 271** that can affect the traversal.
279*/ 272*/
280static int luaB_ipairs (lua_State *L) { 273static int luaB_ipairs (lua_State *L) {
281 lua_CFunction iter = 274 lua_CFunction iter = (luaL_getmetafield(L, 1, "__index") != LUA_TNIL)
282 (luaL_getmetafield(L, 1, "__len") != LUA_TNIL || 275 ? ipairsaux : ipairsaux_raw;
283 luaL_getmetafield(L, 1, "__index") != LUA_TNIL)
284 ? ipairsaux : ipairsaux_raw;
285#if defined(LUA_COMPAT_IPAIRS) 276#if defined(LUA_COMPAT_IPAIRS)
286 return pairsmeta(L, "__ipairs", 1, iter); 277 return pairsmeta(L, "__ipairs", 1, iter);
287#else 278#else