Use string unions instead of generic string

Post Reply
User avatar
_CodeGreen
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat Mar 05, 2022 11:30 am
Contact:

Use string unions instead of generic string

Post by _CodeGreen »

There are a number of places where things like function parameters and concept fields have a type of string, but can only be strings from a defined list.
Would it be possible to make those unions, that way they show up in the autocomplete list when using FMTK + LuaLS?
It's not the end of the world because they still show up in the tooltip, but it would be nice to not have to type some of the longer ones out.

Examples:
LuaItemStack::get_mapper() and set_mapper()
TrainPathFinderRequest::type
ElemID::type
There are plenty more, I won't list them for brevity.
My Mods | If you can't make it perfect, make it adjustable

Bilka
Factorio Staff
Factorio Staff
Posts: 3157
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Use string unions instead of generic string

Post by Bilka »

Thanks for noting this, I fixed the listed methods/attributes and checked and fixed the following classes for the next release (1.1.102):
LuaItemStack
LuaStyle
LuaGuiElement
LuaEntity
LuaEntityPrototype
LuaItemPrototype
LuaLogisticNetwork
LuaGameScript
ItemPrototypeFilters
EntityPrototypeFilters
every type on https://lua-api.factorio.com/latest/concepts.html except the rest of the prototype and event filters.

For other types I'd appreciate if you could note instances when you come across them (either here or in new threads, doesn't matter). The above list of fixes is based what I found with a few searches and the classes that I had noted down already in my own notes, but I expect that I missed a bunch of things.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
_CodeGreen
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Sat Mar 05, 2022 11:30 am
Contact:

Re: Use string unions instead of generic string

Post by _CodeGreen »

Thanks for fixing those!

I went through every class searching for [or "] and found a couple more:
LuaCustomInputPrototype::consuming
LuaFluidBoxPrototype::production_type
LuaRendering::set_alignment
LuaRendering::set_vertical_alignment
LuaSurface::create_entity.type for underground-belt
My Mods | If you can't make it perfect, make it adjustable

Bilka
Factorio Staff
Factorio Staff
Posts: 3157
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Use string unions instead of generic string

Post by Bilka »

Thanks, those are good finds! Fixed for the next release (1.1.102).
I found a few more on LuaRendering (get_type and the rest of the alignment methods) and on LuaSurface, there it was mostly ForceIdentification being listed as only string or Force.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Resolved Requests”