Skip to content

WIP: Fix ipairs() for enum attrs - #1973

Draft
lethosor wants to merge 5 commits into
DFHack:developfrom
lethosor:fix-enum-attrs-ipairs
Draft

lethosor wants to merge 5 commits into
DFHack:developfrom
lethosor:fix-enum-attrs-ipairs

Conversation

@lethosor

@lethosor lethosor commented Sep 29, 2021 •

Copy link
Copy Markdown
Member

Fixes #1860

(Note: I had put this together but evidently never finished it - need to investigate what is missing)

Edit: looks like I didn't make the test pass - that sounds familiar to me now.

@lethosor lethosor self-assigned this Sep 29, 2021
@lethosor
lethosor force-pushed the fix-enum-attrs-ipairs branch from fd01fe9 to f6fe6fb Compare April 1, 2022 04:09
@myk002

myk002 commented May 13, 2022

Copy link
Copy Markdown
Member

this does address a legitimate issue. do you think you will be able to get this done within the release cycle?

@lethosor

lethosor commented Jun 4, 2022

Copy link
Copy Markdown
Member Author

Looking at this again. The Lua layer here is a bit complicated, so no promises.

@lethosor
lethosor force-pushed the fix-enum-attrs-ipairs branch from f6fe6fb to 6fc85a6 Compare June 4, 2022 19:46
@lethosor

lethosor commented Jun 4, 2022

Copy link
Copy Markdown
Member Author

I looked into this some. Turns out this is broken because I'm calling an existing ipairs() implementation that uses rawget():

lua_rawgeti(L, lua_upvalueindex(1), i);

but the attrs table is not actually populated, and instead uses the __index method to return values, which rawget() ignores:

dfhack/library/LuaWrapper.cpp

Lines 1534 to 1536 in f290b1c

lua_pushcclosure(state, meta_enum_attr_index, 3);
freeze_table(state, false, (eid->getFullName()+".attrs").c_str());

so a solution would likely involve a custom ipairs() implementation or changing attrs so that it is populated for all valid enum items.

By the way, the reason for this implementation is probably because indexing attrs with an invalid index returns a table of the default attribute values. So I am leaning towards the former as a solution (a custom ipairs() instead of reusing wtype_ipairs()).

@ab9rf

ab9rf commented Sep 22, 2026

Copy link
Copy Markdown
Member

This is probably superseded by #5966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipairs() called on enum attr tables never ends

3 participants