Code: Select all
[ value1, value2, ... ]
Code: Select all
[]
Code: Select all
{}
Code: Select all
[ value1, value2, ... ]
Code: Select all
[]
Code: Select all
{}
Interesting to know! The prototype docs just specified some types to be array[union] which is how I ended up at the assumption that they are arrays and that tripped when trying to deserialize "{}" as an array.Rseding91 wrote: Sat Oct 07, 2023 3:08 am All types in data.raw are dictionaries with anything looking like an array being numeric-dictionaries
We use the term "array" to mean "you don't need to care about the key values" but Lua itself only supports dictionaries (actually hash-maps under the hood).BrainGamer_ wrote: Sat Oct 07, 2023 7:09 am Interesting to know! The prototype docs just specified some types to be array[union] which is how I ended up at the assumption that they are arrays and that tripped when trying to deserialize "{}" as an array.
Makes sense. I still need to care about it in some way tho since the JSON changes "type" from being an array to a map when the "array" (or internal hash-map) is emptyRseding91 wrote: Sat Oct 07, 2023 2:32 pm We use the term "array" to mean "you don't need to care about the key values"
Code: Select all
"flags":
[
"placeable-neutral",
"player-creation"
],
Code: Select all
"flags":
{},
Code: Select all
"flags":
[],
The fun thing is that this is not the only valid representation for this! Since Lua basically does everything with HashMaps like Rseding said you can have the following:moon69 wrote: Fri Nov 10, 2023 3:54 pmCode: Select all
"flags": [ "placeable-neutral", "player-creation" ],
Code: Select all
"flags":
{
1: "placeable-neutral",
2: "player-creation"
}
Code: Select all
"flags":
{
"1": "placeable-neutral",
"2": "player-creation"
}
C++ takes the raw data.raw from Lua and dumps it as json. No processing or validation is done, e.g. values that the game only reads as integers will still be Lua's doubles which sometimes leads to confusion: viewtopic.php?p=593577#p593577.Geheim wrote: Fri Feb 14, 2025 1:23 pm Ran into this as well with version 2.0.34. Just to understand the dumping process better: Is the JSON generated directly from Lua or with C++ after data.raw was parsed?
The types in the API docs are defined by hand, based on what the C++ source code loads.How are the types from the API docs generated?
No. But there are machine readable docs available at https://lua-api.factorio.com/latest/aux ... otype.html and tools like FMTK use them to support type annotations for Lua: 106458Is the same type information available during the data dump?