Page 1 of 1

MapSettings doesn't specify it returns userdata

Posted: Thu Oct 31, 2024 2:06 am
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.

Re: MapSettings doesn't specify it returns userdata

Posted: Thu Oct 31, 2024 6:12 pm
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.

Re: MapSettings doesn't specify it returns userdata

Posted: Thu Oct 31, 2024 6:21 pm
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