MapSettings doesn't specify it returns userdata

Place to report issues and suggest improvements to the API documentation.
User avatar
PennyJim
Long Handed Inserter
Long Handed Inserter
Posts: 68
Joined: Wed Jan 18, 2023 3:49 am
Contact:

MapSettings doesn't specify it returns userdata

Post by PennyJim »

MapSettings turns out to return userdata.

I was under the false assumption that assigning a table to any of the MapSettings fields needs all the fields filled in. There might be a way to correct that assumption, but that's not what caught me so flat footed.
When I took a returned 'table', attempted to modify a single field in it, and then set the whole table to the field I got it from. It errored because what I gave it was in fact userdata.

Maybe this type of behavior is inherit to LuaStruct I just got told that's how LuaStruct is, so maybe we can get a page describing more about LuaStruct?
Either way, the clarification that you can assign to a field of the returned objects just fine would've been helpful.
curiosity
Filter Inserter
Filter Inserter
Posts: 484
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: MapSettings doesn't specify it returns userdata

Post by curiosity »

How it is currently said:
https://lua-api.factorio.com/latest/cla ... p_settings
map_settings :: Read MapSettings

The currently active set of map settings. Even though this property is marked as read-only, the members of the dictionary that is returned can be modified mid-game.
User avatar
PennyJim
Long Handed Inserter
Long Handed Inserter
Posts: 68
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: MapSettings doesn't specify it returns userdata

Post by PennyJim »

Which I took to mean, the immediate properties of the returned object are writable. When in fact, the returned objects from that returned object are also writable and are in fact not tables.

So the MapSettings properly describes that its fields are read/write, while the types of its fields are described to be just tables, which is what I have a problem with. I understand describing a difference in reading and writing is a little weird to do (and functionally impossible with luals), but it doesn't even mention that it could return userdata
Post Reply

Return to “Documentation Improvement Requests”