table_util¶
Source: base/tealdef/scripts/table_util.d.tl
Notes
Types of /scripts/table_util.tl (TableUtil): deep comparison and copying of tables and simple
array search helpers. Load it with local table_util = ug_require "/scripts/table_util.tl" as TableUtil.
TableUtil¶
record global base/tealdef/scripts/table_util.d.tl:3
global record TableUtil
Load: local table_util = ug_require "/scripts/table_util.tl"
Notes
Table helpers returned by ug_require "/scripts/table_util.tl".
Functions
deepEquals(arg1 : any, arg2 : any, allowFunctions? : boolean, key? : any) : boolean base/tealdef/scripts/table_util.d.tl:4
Call as table_util.deepEquals
Notes
Recursively compares two values; tables are equal when they have the same keys with deeply equal values.
| Parameter | Type | Description |
|---|---|---|
arg1 |
any |
First value. |
arg2 |
any |
Second value. |
allowFunctions? |
boolean |
If true, functions are compared by identity. Otherwise comparing functions logs an error, unless both tables carry a <key>_compareProxy sibling value (compared instead) or the key ends in ecipe. |
key? |
any |
Key under which the values are stored; used for function comparison and error messages. |
Returns boolean: True if the values are deeply equal.
Details
Userdata values must implement an equals method; it is called for the comparison.
Used in the base game: 144 times in 50 files
base/content/industries/industryutil.lua:420
base/content/vehicle/vehicle_modifier.script.tl:89
base/content/landmarks/landmarks.script.tl:185
if not table_util.deepEquals(town2construction[town], landmarksState.town2carrier2modifiers[town]) then
base/content/base/base/difficulty_util.tl:213
base/content/mission/mission/mission_sim.script.tl:788
base/content/mission/mission/mission_react_util.tl:446
… and 44 more files.
copy<T>(obj : T) : T base/tealdef/scripts/table_util.d.tl:5
Call as table_util.copy
Notes
Deep copy of a table (keys and values copied recursively); non-table values are returned unchanged.
Returns T
Details
Metatables are not copied, so vectors from vec3.new lose their operators.
Used in the base game: 239 times in 68 files
base/content/vehicle/vehicle_modifier.script.tl:112
base/content/climates/climates/gen/mapgenutil.tl:126
base/content/infrastructure/bridge/bridge/bridgeutil.lua:207
base/content/infrastructure/bridge/bridge/bridgeutil2.lua:213
base/content/mission/mission/mission_sim.script.tl:570
base/content/mission/mission/mission_task_util.tl:101
… and 62 more files.
shallowCopy<T>(obj : T) : T base/tealdef/scripts/table_util.d.tl:6
Call as table_util.shallowCopy
Notes
Copies the top-level key/value pairs of a table into a new table; nested tables are shared.
Returns T
Used in the base game: 67 times in 20 files
base/content/mission/mission/mission_react_util.tl:234
base/content/mission/mission/mission_task_util.tl:110
base/content/mission/mission/mission_framework/mission_framework_react_util.tl:260
base/content/mission/mission/mission_framework/mission_framework_react.tl:997
base/content/gui/gui/layers/layer_infrastructure.tl:221
base/content/gui/gui/map_editor/map_editor.tl:405
… and 14 more files.
arrayFind<T>(arr : {T}, value : T) : integer base/tealdef/scripts/table_util.d.tl:7
Call as table_util.arrayFind
Notes
Index of the first element equal (==) to value.
Returns integer: The 1-based index, or 0 if the value is not in the array.
Used in the base game: 13 times in 7 files
base/content/mission/mission/mission_framework/mission_framework_react.tl:1060
base/content/mission/mission/tasks/subsidies/guide_subsidies.tl:36
base/content/gui/gui/game_bar/game_bar_widgets.tl:353
base/content/gui/gui/menu/mod_manager_react_util.tl:2335
base/content/gui/gui/main/town_hud_react_util.tl:16
base/content/gui/gui/main/industry_util.tl:568
… and 1 more files.
arrayFindIf<T>(arr : {T}, pred : function(T) : boolean) : integer base/tealdef/scripts/table_util.d.tl:8
Call as table_util.arrayFindIf
Notes
Index of the first element for which pred returns true.
Returns integer: The 1-based index, or 0 if no element matches.
Used in the base game: 5 times in 4 files
base/content/gui/gui/construction/construction.tl:970
local index = table_util.arrayFindIf(objects, function(object : MenuCategoryUtil.FilterObject) : boolean
base/content/gui/gui/main/menu_category_util.tl:368
local buttonIndex = table_util.arrayFindIf(param.filterBoxParam.objectsSorted, function(object : MenuCategoryUtil.FilterObject) : boolean
base/content/gui/gui/entity_window/bridge_and_tunnel.tl:109
if table_util.arrayFindIf(newState.availableObjects, function(object : MenuCategoryUtil.FilterObject) : boolean
base/content/game_mechanics/game_mechanics/company/explorations/exploration_plane.script.tl:300
arrayRemove<T>(arr : {T}, value : T) : boolean base/tealdef/scripts/table_util.d.tl:9
Call as table_util.arrayRemove
Notes
Removes the first element equal to value from the array, in place.
Returns boolean: True if an element was removed.
arrayContains<T>(arr : {T}, value : T) : boolean base/tealdef/scripts/table_util.d.tl:10
Call as table_util.arrayContains
Notes
True if the array contains an element equal (==) to value.
Returns boolean
Used in the base game: 108 times in 32 files
base/content/mission/mission/mission_sim.script.tl:976
base/content/mission/mission/mission_savegame_util.tl:34
base/content/mission/mission/mission_framework/mission_framework_react.tl:1067
base/content/mission/mission/tutorial/tutorial_story_branch_b.tl:108
if table_util.arrayContains(stock.cargoTypes.cargoClassesIncluded, "GOODS") or table_util.arrayContains(stock.cargoTypes.cargoClassesIncluded, "UNIVERSAL") then
base/content/mission/mission/tutorial/tutorial_story_branch_a.tl:109
if table_util.arrayContains(stock.cargoTypes.cargoClassesIncluded, "LIQUID") or table_util.arrayContains(stock.cargoTypes.cargoClassesIncluded, "UNIVERSAL") the
base/content/mission/mission/tutorial/tutorial_story_util.tl:113
… and 26 more files.
find<K, V>(dict : {{K, V}}, key : K) : V base/tealdef/scripts/table_util.d.tl:11
Call as table_util.find
Notes
Looks up key in a list of {key, value} pairs.
Returns V: The value of the first pair whose first element equals key, or nil.
concatenate<T>(...: {T}) : {T} base/tealdef/scripts/table_util.d.tl:12
Call as table_util.concatenate
Notes
Returns a new array with the elements of all given arrays, in order.
Returns {T}
Used in the base game: 28 times in 16 files
base/content/mission/mission/tasks/create_line/create_line.tl:41
base/content/mission/mission/tasks/build_construction/build_construction_variant.tl:61
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:4868
local colorChooserColorsStaticData = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_c
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:3600
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:275
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:601
… and 10 more files.
merge<T, V>(...: {T : V}) : {T : V} base/tealdef/scripts/table_util.d.tl:13
Call as table_util.merge
if same key is in multiple tables, the last one wins.
Returns {T : V}
Used in the base game: 11 times in 3 files
base/content/gui/gui/menu/graphics_presets_util.tl:169
mods/release/urbangames_campaign_mission_02/content/mission/mission/mission_story.tl:80
local allowBuyVehiclesAfterTrainExtension : {string : integer} = table_util.merge(allowBuyVehiclesTrainExtension)
mods/release/urbangames_campaign_mission_05/content/mission/mission/mission_story.tl:527
removeDuplicates<T>(arr : {T}) : {T} base/tealdef/scripts/table_util.d.tl:14
Call as table_util.removeDuplicates
Notes
Returns a new array with repeated elements removed, keeping the first occurrence and the order.
Returns {T}
Used in the base game: 2 times in 2 files
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:367
base/content/gui/gui/main/cargo_react_util.tl:704