ug4

Functions

function table append (t1, t2)
 
function table contains (t, value)
 
function table deepcopy (t)
 
function table ideepcopy (t)
 
function iipairs (tab)
 
function table imax (t)
 
function table imin (t)
 
function table ishallowcopy (t)
 
function table len_of_longest_identifyer (t)
 
function table merge (t1, t2)
 
function table merge_inplace (t1, t2)
 
function table print (data, style)
 
function table print_flat (t, prefix, maxLen)
 
function table shallowcopy (t)
 

Detailed Description

Utility functions for easy but advanced table access.

Function Documentation

◆ append()

◆ contains()

function table contains ( ,
value   
)

checks if a value is contained in a table

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :151-156

function table.contains(t, value)
for _,v in pairs(t) do
if v == value then return true end
end
return false
end

Referenced by ug::GetElemDiscItemOnSubset(), ug::SurfaceView::mark_shadowing(), and ug::bridge::RegisterDegeneratedLayerManager().

◆ deepcopy()

function table deepcopy ( )

returns deep-copy of table (i.e., copies recursive all contained tables as well)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :84-96

function table.deepcopy(t)
local copy
if type(t) == "table" then
copy = {}
for k, v in next, t, nil do
copy[table.deepcopy(k)] = table.deepcopy(v)
end
setmetatable(copy, table.deepcopy(getmetatable(t)))
else -- number, string, boolean, etc
copy = t
end
return copy
end
double number
Definition: types.h:124
int local(bglp_vertex_descriptor p)
Definition: parallel_matrix.h:57

◆ ideepcopy()

function table ideepcopy ( )

returns deep-copy of integer-key part of table (i.e., copies recursive all contained tables as well)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :99-110

function table.ideepcopy(t)
local copy
if type(t) == "table" then
copy = {}
for k, v in ipairs(t) do
copy[k] = table.deepcopy(v)
end
else -- number, string, boolean, etc
copy = t
end
return copy
end

◆ iipairs()

function iipairs ( tab  )

returns iterator function iterating through first consecutive integer-key range (even starting at negative or null)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :135-147

function iipairs(tab)
local n = table.imin(tab)-1
local t = tab
return function (i)
n = n + 1
local v = t[n]
if v then
return n, v
else
return nil
end
end
end
function iipairs(tab)

◆ imax()

function table imax ( )

returns the largest integer key of the table (even in non-consecutive arrays)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :124-132

function table.imax(t)
local max = -math.huge
for k, _ in pairs(t) do
if type(k) == "number" and math.floor(k)==k then
max = math.max(max, k)
end
end
return max
end

◆ imin()

function table imin ( )

returns the smallest integer key of the table (even negative or null if present)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :113-121

function table.imin(t)
local min = math.huge
for k, _ in pairs(t) do
if type(k) == "number" and math.floor(k)==k then
min = math.min(min, k)
end
end
return min
end

◆ ishallowcopy()

function table ishallowcopy ( )

returns shallow-copy of integer-key part of table (i.e., only top level values)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :69-80

function table.ishallowcopy(t)
local copy
if type(t) == "table" then
copy = {}
for k, v in ipairs(t) do
copy[k] = v
end
else -- number, string, boolean, etc
copy = t
end
return copy
end

◆ len_of_longest_identifyer()

function table len_of_longest_identifyer ( )

traverses a table recursively and returns the length of the longest identifyer

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :245-255

function table.len_of_longest_identifyer(t)
local maxLen = 0
for n, v in pairs(t) do
if type(v) == "table" then
maxLen = math.max(maxLen, table.len_of_longest_identifyer(v))
else
maxLen = math.max(maxLen, string.len(n))
end
end
return maxLen
end

References s.

◆ merge()

function table merge ( t1  ,
t2   
)

Creates a new table which contains the entries from tables t1 and t2. key-value pairs from table t1 have higher priority than those from t2, meaning that if a key is found in both tables, the key-value pair from t1 is considered only.

Returns
A new table resulting from merging t1 and t2

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :320-324

function table.merge(t1, t2)
local t = table.deepcopy(t1)
table.merge_inplace(t, t2)
return t
end

Referenced by ug::MergeGlobalLayout(), and ug::MergeInterfaces().

◆ merge_inplace()

function table merge_inplace ( t1  ,
t2   
)

Recursively adds entries from table t2 to table t1, if those entries were not already contained in t1.

Returns
t1

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :300-313

function table.merge_inplace(t1, t2)
for n, v in pairs(t2) do
if type(v) == "table" then
if t1[n] == nil then
t1[n] = table.deepcopy(v)
elseif type(t1[n]) == "table" then
table.merge_inplace(t1[n], v)
end
elseif t1[n] == nil then
t1[n] = v
end
end
return t1
end

◆ print()

◆ print_flat()

function table print_flat ( ,
prefix  ,
maxLen   
)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :258-294

◆ shallowcopy()

function table shallowcopy ( )

returns shallow-copy of table (i.e., only top level values)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / table_util.lua :55-66

function table.shallowcopy(t)
local copy
if type(t) == "table" then
copy = {}
for k, v in pairs(t) do
copy[k] = v
end
else -- number, string, boolean, etc
copy = t
end
return copy
end