Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipairs() called on enum attr tables never ends #1860

Open
lethosor opened this issue May 27, 2021 · 2 comments · May be fixed by #1973
Open

ipairs() called on enum attr tables never ends #1860

lethosor opened this issue May 27, 2021 · 2 comments · May be fixed by #1973
Assignees
Labels

Comments

@lethosor
Copy link
Member

To reproduce:

[lua]# @df.item_type
...
90                     	 = BRANCH
[lua]# @df.item_type.attrs
...
111655                 	 = <item_type._attr_entry_type: 0x7ffff7dcfca0>
...

This can be stopped with kill-lua if run with dfhack-run (since printall_ipairs() is pure Lua).

Reported by @wolfboyft on Discord

@Tachytaenius
Copy link
Contributor

I guess there shouldn't really be a notion of ipairs on it, then. Unless the format does have a sensible end? Either way, it feels more like a function actually-- decodeTileInfo or whatever. Ykwim?

@lethosor
Copy link
Member Author

lethosor commented May 27, 2021

There definitely is a logical "end" - the attrs table stores attributes about each enum item, and there are a fixed number of those. That's what my comparison to the behavior of @df.item_type was intended to demonstrate - ipairs() on an enum does end.

However, the Lua layer (maybe also C++) has a "default" attributes object for any enum items that aren't defined, which also includes values past the end of the enum. Here's another example. 1 and 2 are valid item_types, but 999 and 9999 are not, and the last two refer to the exact same table.

[lua]# !df.item_type.attrs[1]
<item_type._attr_entry_type: 0x7ffff7dcf430>
[lua]# !df.item_type.attrs[2]
<item_type._attr_entry_type: 0x7ffff7dcf448>
[lua]# !df.item_type.attrs[999]
<item_type._attr_entry_type: 0x7ffff7dcfca0>
[lua]# !df.item_type.attrs[9999]
<item_type._attr_entry_type: 0x7ffff7dcfca0>

So while we do want invalid indexes to continue to work, we should make ipairs(some_enum.attrs) stop at the same place as ipairs(some_enum) to fix this.

lethosor added a commit to lethosor/dfhack that referenced this issue Jun 19, 2021
ipairs() currently fails due to DFHack#1860
@lethosor lethosor self-assigned this Jun 19, 2021
@lethosor lethosor linked a pull request Sep 29, 2021 that will close this issue
lethosor added a commit to lethosor/dfhack that referenced this issue Apr 1, 2022
ipairs() currently fails due to DFHack#1860
lethosor added a commit to lethosor/dfhack that referenced this issue Jun 4, 2022
ipairs() currently fails due to DFHack#1860
@myk002 myk002 added this to To do in 0.47.05-r6 via automation Jun 5, 2022
@myk002 myk002 removed this from To do in 0.47.05-r6 Jun 13, 2022
@myk002 myk002 removed the lua label Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants