Lua: support for requirement vectors
My main concern is that the design is such that things remain stable from version to version, as deprecating anything from the lua script is next to impossible. So having internal structures exposed to lua scripts may mean that we can't change those internals.
Reply To cazfi
My main concern is that the design is such that things remain stable from version to version, as deprecating anything from the lua script is next to impossible. So having internal structures exposed to lua scripts may mean that we can't change those internals.
Requirements are not that internal as we set them from rulesets. Requirement factors are well quite backstage but are so firmly tied to the requirements that deprecating existing ones is also very unlikely, only new ones may sometimes arrive, the design I think about is likely more or less resistable to it.
Make a class to get requirement vector properties of unit types etc., as well as create them dynamically for in-script use.
That probably requires creating Lua object type that resides within Lua memory (see comment in the code about destructors in C projects, it's probably still actual). Like this:
We provide methods (Req_Vec):test(elements), (Req_Vec):iterate(), and for editable vectors :insert(pos, {elements}) and :delete(pos). Also, we make module requirements with method .new_vec{table} and .test(req_type, req_range, {elements}, survives?), better with a shortcut to just requirements[ req_type ](...) (e.g., requirements.MaxUnitsOnTile("Local", find.tile(3,14))). "Elements" may be a table with named fields like {city = "Leningrad"} or just a sequence where field is detected by element type (find.city(nil, "Leningrad")). The vector table may look most alike what we have in specfiles {"type", "name", "range"}, {"DiplRel", "IsForeign", "Local"}} or consist of tables with named arguments {{type = "DiplRel", name = "IsForeign", range = "Local ", }}.