Module xbt.util
Utility functions for XBTs.
Info:
- Copyright: 2015, Matthias Hölzl
- License: MIT, see the file LICENSE.md.
- Author: Matthias Hölzl
Functions
random (m, n) | Generate a random bounded integer. |
uuid () | An implementation of version 4 UUIDs. |
size (t) | Compute the size of a table. |
equal (t1, t2, cache) | Value equality for tables. |
keys (t) | Return a list containing the keys of a table. |
addall (t1, t2) | Conjoin the members of one table to another. |
append (t1, t2) | Append two arrays. |
maybe_add (table, attribute, value) | Add an attribute to a table if it doesn't already exist. |
debug_print (...) | Print arguments when debugging is enabled. |
Fields
rng | The central random number generator. |
debug | A flag indicating whether debug output should be shown. |
Functions
- random (m, n)
-
Generate a random bounded integer.
The generated integer is between
m
andn
(inclusive) if two arguments are provided, otherwise it is between1
andn
.Parameters:
- m The lower bound of the generated numbers (inclusive) if a second argument is provided, otherwise the upper bound.
- n The upper bound of the generated number if an argument is provided.
- uuid ()
-
An implementation of version 4 UUIDs.
Generates a V4 (random) unique identifier represented as a string.
Returns:
-
A string in UUID V4 format.
- size (t)
-
Compute the size of a table.
This includes all attributes and array members.
Parameters:
- t A table
Returns:
-
The number of attributes of
t
. - equal (t1, t2, cache)
-
Value equality for tables.
Check whether two tables are equal as values. Recursively descends
into attributes. All other values are compared using
==
. Ignoeres metatables.Parameters:
- t1 A table.
- t2 A table.
- cache A cache for values that have already been compared
Returns:
true
ift1
andt2
have the same value,false
otherwise. - keys (t)
-
Return a list containing the keys of a table.
Parameters:
- t A table.
Returns:
-
The keys of
t
sorted alphabetically. - addall (t1, t2)
-
Conjoin the members of one table to another.
Parameters:
- t1 The table to which the new values are added. Modified destructively.
- t2 The table containing the new keys
Returns:
t1
, modified with the key/value bindings oft2
Keys occurring in both tables get the value oft2
. - append (t1, t2)
-
Append two arrays.
Parameters:
- t1 An array. Destructively modified.
- t2 An array.
Returns:
t1
, extended with the values oft2
- maybe_add (table, attribute, value)
-
Add an attribute to a table if it doesn't already exist.
Parameters:
- table The table to which the attribute is added
- attribute The name of the attribute as string
- value
The value of the attribute. Defaults to
{}
Returns:
-
table, with the
attribute
/value
pair added if no value forattribute
was present, the unmodified table otherwise. - debug_print (...)
-
Print arguments when debugging is enabled.
Parameters:
- ... Any number of arguments will be passed on to print.