seqlua
diff seqlualib.c @ 23:29792283522f
Removed iterator(...) function; ipairs doesn't accept iterator triplets anymore
| author | jbe |
|---|---|
| date | Thu Aug 21 20:01:52 2014 +0200 (2014-08-21) |
| parents | 12a7a8f5a77d |
| children | 367fc70acc15 |
line diff
1.1 --- a/seqlualib.c Thu Aug 21 13:04:45 2014 +0200 1.2 +++ b/seqlualib.c Thu Aug 21 20:01:52 2014 +0200 1.3 @@ -10,13 +10,12 @@ 1.4 luaL_checkany(L, idx); // provides better error message 1.5 iter->L = L; 1.6 iter->idx = idx; 1.7 - if (lua_type(L, idx) == LUA_TFUNCTION) { 1.8 + if ( 1.9 + lua_type(L, idx) == LUA_TFUNCTION || 1.10 + (luaL_getmetafield(L, idx, "__call") && (lua_pop(L, 1), 1)) 1.11 + ) { 1.12 iter->itertype = SEQLUA_ITERTYPE_FUNC; 1.13 - } else if (luaL_getmetafield(L, idx, "__call")) { 1.14 - lua_pop(L, 1); 1.15 - iter->itertype = SEQLUA_ITERTYPE_FUNC; 1.16 - } else if (luaL_getmetafield(L, idx, "__index")) { 1.17 - lua_pop(L, 1); 1.18 + } else if (luaL_getmetafield(L, idx, "__index") && (lua_pop(L, 1), 1)) { 1.19 iter->itertype = SEQLUA_ITERTYPE_META; 1.20 } else { 1.21 luaL_checktype(L, idx, LUA_TTABLE); 1.22 @@ -48,43 +47,3 @@ 1.23 return 1; 1.24 } 1.25 1.26 -static int seqlua_iterclosureaux_raw(lua_State *L) { 1.27 - lua_Integer i = lua_tointeger(L, lua_upvalueindex(2)) + 1; 1.28 - lua_rawgeti(L, lua_upvalueindex(1), i); 1.29 - if (lua_isnil(L, -1)) return 1; 1.30 - lua_pushinteger(L, i); 1.31 - lua_replace(L, lua_upvalueindex(2)); 1.32 - return 1; 1.33 -} 1.34 - 1.35 -static int seqlua_iterclosureaux_meta(lua_State *L) { 1.36 - lua_Integer i = lua_tointeger(L, lua_upvalueindex(2)) + 1; 1.37 - lua_pushinteger(L, i); 1.38 - lua_gettable(L, lua_upvalueindex(1)); 1.39 - if (lua_isnil(L, -1)) return 1; 1.40 - lua_pushinteger(L, i); 1.41 - lua_replace(L, lua_upvalueindex(2)); 1.42 - return 1; 1.43 -} 1.44 - 1.45 -void seqlua_iterclosure(lua_State *L, int idx) { 1.46 - luaL_checkany(L, idx); // provides better error message 1.47 - if (lua_type(L, idx) == LUA_TFUNCTION) { 1.48 - // do nothing 1.49 - } else if (luaL_getmetafield(L, idx, "__call")) { 1.50 - lua_pop(L, 1); 1.51 - } else if (luaL_getmetafield(L, idx, "__index")) { 1.52 - lua_pop(L, 1); 1.53 - lua_pushvalue(L, idx); 1.54 - lua_pushinteger(L, 0); 1.55 - lua_pushcclosure(L, seqlua_iterclosureaux_meta, 2); 1.56 - lua_replace(L, idx); 1.57 - } else { 1.58 - luaL_checktype(L, idx, LUA_TTABLE); 1.59 - lua_pushvalue(L, idx); 1.60 - lua_pushinteger(L, 0); 1.61 - lua_pushcclosure(L, seqlua_iterclosureaux_raw, 2); 1.62 - lua_replace(L, idx); 1.63 - } 1.64 -} 1.65 -