Feature: operations on arrays
Motivation / Problem
As more and more features in NML require users to use arrays it would be reasonable to expand capabilities of array creation.
Description
It allows for creating arrays with following syntax:
[13] * 200
or for more complex repetitive arrays:
[13,12,11,15] * 19 * 8
and with the "embed for" syntax:
[a, a*a, a - 13 for a in [10, 20, 30, 40]] -> [10, 100, -3, 20, 400, 7, 30, 900, 17, 40, 1600, 27]
[palette_switch(a) for a in [0, 5, 6, 10]] -> [palette_switch(0), palette_switch(5), palette_switch(6), palette_switch(10)]
[[a, bitmask(a)] for a in [1, 2, 3]] -> [[1, 2], [2, 4], [3, 8]]
[a, a+2 for a in [param[param[1]], param[0]]] -> [param[param[1]], param[param[1]] + 2, param[0], param[0] + 2]
it also adds support for array addition.
Tests very much needed
Reminder that NML is not a programming language.
What problem does this PR solve?
The checks have caught some errors which are generally self-explanatory.
I also wonder what the intended use of this is: large arrays with repetitive values aren't something I've seen in NML sources.
Reminder that NML is not a programming language.
Acknowledged
What problem does this PR solve?
Provides ability to recreate feature that You have rejected in #385 in the newgrfs.
I also wonder what the intended use of this is: large arrays with repetitive values aren't something I've seen in NML sources.
It is intended to use this for all lengths of array in order to make code more clean, shorter and easier to maintain. The alternative and currently working solution is to use 3-rd party tools to generate nml code at the compile time, this solution is hard to maintain because it demands knowledge of multiple tools.
Tests very much needed
Is the 042_for.nml sufficient