seqlua

diff seqlualib.c @ 6:7b05ca6ef925

Allow seqlua_iterinit to modify the value on stack instead of storing an extra element on stack
author jbe
date Wed Aug 20 01:52:35 2014 +0200 (2014-08-20)
parents 47f9b323d68c
children 2cb22d01fdd0
line diff
     1.1 --- a/seqlualib.c	Wed Aug 20 01:45:04 2014 +0200
     1.2 +++ b/seqlualib.c	Wed Aug 20 01:52:35 2014 +0200
     1.3 @@ -11,9 +11,9 @@
     1.4    iter->L = L;
     1.5    if (luaL_getmetafield(L, idx, "__call")) {
     1.6      if (lua_type(L, -1) != LUA_TFUNCTION) luaL_error(L, "__call is not a function");
     1.7 +    lua_replace(L, idx);
     1.8      iter->itertype = SEQLUA_ITERTYPE_FUNC;
     1.9    } else if (lua_type(L, idx) == LUA_TFUNCTION) {
    1.10 -    lua_pushvalue(L, idx);
    1.11      iter->itertype = SEQLUA_ITERTYPE_FUNC;
    1.12    } else {
    1.13      if (luaL_getmetafield(L, idx, "__index")) {
    1.14 @@ -23,7 +23,6 @@
    1.15        luaL_checktype(L, idx, LUA_TTABLE);
    1.16        iter->itertype = SEQLUA_ITERTYPE_RAW;
    1.17      }
    1.18 -    lua_pushvalue(L, idx);
    1.19    }
    1.20    iter->i = 0;
    1.21  }
    1.22 @@ -44,7 +43,7 @@
    1.23      lua_rawgeti(L, -1, i);
    1.24    }
    1.25    if (lua_isnil(L, -1)) {
    1.26 -    lua_pop(L, 2);
    1.27 +    lua_pop(L, 1);
    1.28      return 0;
    1.29    }
    1.30    return 1;

Impressum / About Us