Skip to content

Commit

Permalink
Implement an enum.attrs.__ipairs that returns the right number of ele…
Browse files Browse the repository at this point in the history
…ments

All values are currently nil
  • Loading branch information
lethosor committed Apr 1, 2022
1 parent 1388a28 commit 64e08e4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions library/LuaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,25 @@ static void FillEnumKeys(lua_State *state, int ix_meta, int ftable, enum_identit
lua_pushcclosure(state, meta_enum_attr_index, 3);

freeze_table(state, false, (eid->getFullName()+".attrs").c_str());
int ix_attrs = lua_gettop(state);

// add metamethods to metatable of .attrs
if (lua_getmetatable(state, ix_attrs))
{
int ix_attrs_meta = lua_gettop(state);

if (eid->getFirstItem() <= eid->getLastItem())
{
lua_pushvalue(state, ix_attrs);
lua_pushinteger(state, eid->getFirstItem() - 1);
lua_pushinteger(state, eid->getLastItem());
lua_pushcclosure(state, wtype_ipairs, 3);
lua_setfield(state, ix_attrs_meta, "__ipairs");
}

lua_pop(state, 1); // pop metatable
}

lua_setfield(state, ftable, "attrs");
}

Expand Down

0 comments on commit 64e08e4

Please sign in to comment.