seqlua
diff seqlualib.c @ 54:92ce3958aca7
Reverted last two commits
author | jbe |
---|---|
date | Wed Aug 27 00:10:47 2014 +0200 (2014-08-27) |
parents | 3362ec36cb09 |
children | da4b9d6a5b7e |
line diff
1.1 --- a/seqlualib.c Tue Aug 26 23:53:29 2014 +0200 1.2 +++ b/seqlualib.c Wed Aug 27 00:10:47 2014 +0200 1.3 @@ -8,11 +8,9 @@ 1.4 #define SEQLUA_ITERTYPE_INDEX 3 1.5 #define SEQLUA_ITERTYPE_RAW 4 1.6 1.7 -void seqlua_iterinit(lua_State *L, seqlua_Iterator *iter, int mode, int idx) { 1.8 - int generated = 0; 1.9 - seqlua_iterinit_repeat: 1.10 +void seqlua_iterinit(lua_State *L, seqlua_Iterator *iter, int idx) { 1.11 if (luaL_getmetafield(L, idx, "__ipairs")) { 1.12 - if (!generated) lua_pushvalue(L, idx); 1.13 + lua_pushvalue(L, idx); 1.14 lua_call(L, 1, 3); 1.15 if (lua_type(L, -3) == LUA_TSTRING) { 1.16 const char *method = lua_tostring(L, -3); 1.17 @@ -31,25 +29,16 @@ 1.18 } 1.19 } else { 1.20 if (lua_type(L, idx) == LUA_TFUNCTION) { 1.21 - if (generated || mode == SEQLUA_MODE_CALL) { 1.22 - iter->itertype = SEQLUA_ITERTYPE_CALL; 1.23 - goto seqlua_iterinit_finish; 1.24 - } else if (mode == SEQLUA_MODE_GENERATOR) { 1.25 - lua_pushvalue(L, idx); 1.26 - lua_call(L, 0, 1); 1.27 - idx = lua_gettop(L); 1.28 - goto seqlua_iterinit_repeat; 1.29 - } 1.30 + iter->itertype = SEQLUA_ITERTYPE_CALL; 1.31 } else if (luaL_getmetafield(L, idx, "__index")) { 1.32 lua_pop(L, 1); 1.33 iter->itertype = SEQLUA_ITERTYPE_INDEX; 1.34 - goto seqlua_iterinit_finish; 1.35 + } else { 1.36 + luaL_checktype(L, idx, LUA_TTABLE); 1.37 + iter->itertype = SEQLUA_ITERTYPE_RAW; 1.38 } 1.39 - luaL_checktype(L, idx, LUA_TTABLE); 1.40 - iter->itertype = SEQLUA_ITERTYPE_RAW; 1.41 - seqlua_iterinit_finish: 1.42 // always occupy 3 stack indicies 1.43 - if (!generated) lua_pushnil(L); 1.44 + lua_pushnil(L); 1.45 lua_pushnil(L); 1.46 lua_pushnil(L); 1.47 iter->idx = idx;