Fix complex enum ipairs for first element

develop
lethosor 2018-04-09 11:27:02 -04:00
parent 61539bf345
commit c1dd21730d
1 changed files with 5 additions and 3 deletions

@ -1375,9 +1375,11 @@ static bool complex_enum_next_item_helper(lua_State *L, int64_t &item)
static int complex_enum_inext(lua_State *L) static int complex_enum_inext(lua_State *L)
{ {
int64_t first_item = ((enum_identity::ComplexData*)lua_touserdata(L, lua_upvalueindex(2)))->index_value_map[0]; bool is_first = lua_isuserdata(L, 2);
int64_t i = (lua_isuserdata(L, 2)) ? first_item : luaL_checkint(L, 2); int64_t i = (is_first)
if (complex_enum_next_item_helper(L, i)) ? ((enum_identity::ComplexData*)lua_touserdata(L, lua_upvalueindex(2)))->index_value_map[0]
: luaL_checkint(L, 2);
if (is_first || complex_enum_next_item_helper(L, i))
{ {
lua_pushinteger(L, i); lua_pushinteger(L, i);
lua_rawgeti(L, lua_upvalueindex(1), i); lua_rawgeti(L, lua_upvalueindex(1), i);