Skip to content

Commit dde88dd

Browse files
committed
Implement an enum.attrs.__ipairs that returns the right number of elements
All values are currently nil
1 parent 7bb1cdc commit dde88dd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

library/LuaWrapper.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,25 @@ static void FillEnumKeys(lua_State *state, int ix_meta, int ftable, enum_identit
15341534
lua_pushcclosure(state, meta_enum_attr_index, 3);
15351535

15361536
freeze_table(state, false, (eid->getFullName()+".attrs").c_str());
1537+
int ix_attrs = lua_gettop(state);
1538+
1539+
// add metamethods to metatable of .attrs
1540+
if (lua_getmetatable(state, ix_attrs))
1541+
{
1542+
int ix_attrs_meta = lua_gettop(state);
1543+
1544+
if (eid->getFirstItem() <= eid->getLastItem())
1545+
{
1546+
lua_pushvalue(state, ix_attrs);
1547+
lua_pushinteger(state, eid->getFirstItem() - 1);
1548+
lua_pushinteger(state, eid->getLastItem());
1549+
lua_pushcclosure(state, wtype_ipairs, 3);
1550+
lua_setfield(state, ix_attrs_meta, "__ipairs");
1551+
}
1552+
1553+
lua_pop(state, 1); // pop metatable
1554+
}
1555+
15371556
lua_setfield(state, ftable, "attrs");
15381557
}
15391558

0 commit comments

Comments
 (0)