Utilities¶
Functions on tables¶
-
halmd.utility.
empty
(t)¶ Test if table is empty.
-
halmd.utility.
keys
(t)¶ Returns table with sorted keys of table t as values.
-
halmd.utility.
sorted
(t)¶ Returns iterator over pairs of table t sorted by key.
-
halmd.utility.
reverse
(t)¶ Returns table with keys as values and values as keys.
-
halmd.utility.
table_shallow_copy
(t)¶ Create a shallow copy of a table, i.e., return a new table with shallow copies of all the original table’s elements.
-
halmd.utility.
repeat_element
(x, n)¶ Return an array with x n-times repeated (at keys 1, …, n).
If x is a table, shallow copies of its elements are created.
-
halmd.utility.
concat
(t1, t2)¶ Concatenates two tables t1 and t2.
Only the array part of the tables are used, i.e., elements with integer indices.
Functions on strings¶
-
halmd.utility.
interp
(s, t)¶ Interpolate strings supporting Pythonic formatting specifications (see http://lua-users.org/wiki/StringInterpolation, example by RiciLake)
Parameters: - s (string) – formatting string
- t (table) – (key, value) pairs
Returns: interpolated copy of string ‘s’
Occurrences of ‘{key:fmt}’ in the formatting string are substituted by ‘(“%fmt”):format(value)’, where ‘fmt’ is one of the C-printf formatting codes. The method is added to the string type as string.interp.
Example:
print( (“{name:s} is {val:7.2f}%”):interp({name = “concentration”, val = 56.2795}) )
–> “concentration is 56.28%”
Assertions¶
-
halmd.utility.
assert_kwarg
(args, key, level)¶ Assert keyword argument of table and return its value.
Parameters: - args (table) – argument table
- key (string) – parameter key
- level (number) – call stack level for error message (default: 2)
Returns: args[key]
-
halmd.utility.
assert_type
(var, name, level)¶ Assert type of variable.
Parameters: - var – variable to check
- name (string) – Lua type name
- level (number) – call stack level for error message (default: 2)
Returns: var