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

Enum attrs bi-directional mapping #6

Open
vallode opened this issue Apr 24, 2024 · 1 comment
Open

Enum attrs bi-directional mapping #6

vallode opened this issue Apr 24, 2024 · 1 comment

Comments

@vallode
Copy link
Owner

vallode commented Apr 24, 2024

Enum attributes can be access either via the key or the value of the corresponding enum, right now we are only using the value. This results in some annoying behaviour:

---@type tiletype
local ttype = dfhack.maps.getTileType(engraving.pos)
local tileattrs = df.tiletype.attrs[ttype] -- Cast as `unknown` even though this is a valid index.

The biggest issue is going to be figuring out how to do this without doubling the size of enums (again):

---@field FrozenRampTrackNEW { caption: "ice ramp track NEW", shape: "RAMP", material: "FROZEN_LIQUID", variant: "NONE", special: "TRACK", direction: "NEW" }```

Would change into:

---@field FrozenRampTrackNEW { caption: "ice ramp track NEW", shape: "RAMP", material: "FROZEN_LIQUID", variant: "NONE", special: "TRACK", direction: "NEW" }
---@field [677] { caption: "ice ramp track NEW", shape: "RAMP", material: "FROZEN_LIQUID", variant: "NONE", special: "TRACK", direction: "NEW" }

For enums with hundreds of attributes, it is less than ideal.

@vallode
Copy link
Owner Author

vallode commented Apr 28, 2024

Even more annoyingly, it looks like accessing known class fields by a known integer variable is unsupported in LuaLS:

---@class Foo
---@field [0] "I am a string"
local foo

local bar = 0

local test = foo[bar] -- This _should_ result in test being known, but it is marked as "unknown" instead.

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

No branches or pull requests

1 participant