dfhack icon indicating copy to clipboard operation
dfhack copied to clipboard

WIP: Fix ipairs() for enum attrs

Open lethosor opened this issue 4 years ago • 3 comments

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 avatar Sep 29 '21 00:09 lethosor

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

myk002 avatar May 13 '22 03:05 myk002

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

lethosor avatar Jun 04 '22 19:06 lethosor

I looked into this some. Turns out this is broken because I'm calling an existing ipairs() implementation that uses rawget(): https://github.com/DFHack/dfhack/blob/f290b1c804f6207afc786b3a3ca83e8cd87c44d9/library/LuaWrapper.cpp#L1343

but the attrs table is not actually populated, and instead uses the __index method to return values, which rawget() ignores: https://github.com/DFHack/dfhack/blob/f290b1c804f6207afc786b3a3ca83e8cd87c44d9/library/LuaWrapper.cpp#L1534-L1536

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()).

lethosor avatar Jun 04 '22 22:06 lethosor