Section Tables

tables utility functions.

Summary

Return typeFunction and summary
 ArrayClear(table t)
Optimization of clearing a table.
booleanArrayContains(table tab, term)
Does tab contains term?
booleanIN(term, ...)
Check if term is in the list of following arguments.
booleanassertInArray(value, table t, string text, boolean visual)
Assert a value is found in a table.
booleanisTable(obj)
Returns true if obj is a table or a MyrScript object represented as a table such as Score or Target.
stringstring_join(table list, string delimiter)
Concat the elements of table list, separated by the string delimiter.
tablestring_split(string s, string delim, int limit)
Split the string s by a string delimiter delim.
tablestring_split_lines(string s)
Split the string s by lines, handle \r, \n and \r\n.
 table_insert_multi(table t, ...)
Insert multiple items in a table in one call.
 tdebug(...)
Return the structure of a table, Collection or Map for debugging to the console.

Functions

assertInArray(value, table t, string text, boolean visual)

Assert a value is found in a table.

ParameterTypeDefaultDescription
value  number or string. nil always fails the assertion.
ttable List of values in which value is searched for.
textstring Text to print on console and throw if expr ~= expected
visualbooleanfalseVisual alert. Does not stop the script with a console error message, returns true if assertion is correct, nil if it fails.
Your script must handle the returned value to stop gracefully.
Return
boolean: true if assertion is correct, nil (for false) if it failed. If visual ~= true, no need to check the returned value, script will die with a console error.
Error
If value not found in t

IN(term, ...)

Check if term is in the list of following arguments.

ParameterTypeDefaultDescription
term  string, number or objects that support == comparison
...  List of arguments, of undefined length. If one (or more) arguments are table, Collection or Map then term is searched in their items.
Note that Collection and Map values must have the same type than type(term).
Return
boolean: true if the list contains term, nil (for false) if the list doesn't contains term
See
ArrayContains

isTable(obj)

Returns true if obj is a table or a MyrScript object represented as a table such as Score or Target.

ParameterTypeDefaultDescription
obj  obj
Return
boolean: boolean

ArrayClear(table t)

Optimization of clearing a table.

tremove is time consuming because it shift all items after the removed one.
tremove from last to first would be a bit faster.
but setting items to nil is even faster.

ParameterTypeDefaultDescription
ttable The table to clear.

ArrayContains(table tab, term)

Does tab contains term?

ParameterTypeDefaultDescription
tabtable A table of numbers or strings
term  A number or a string to find in tab
Return
boolean: true, or nil (for false)
Error
if tab's items are not comparable with term

tdebug(...)

Return the structure of a table, Collection or Map for debugging to the console.

ParameterTypeDefaultDescription
...  Structure(s) to debug

table_insert_multi(table t, ...)

Insert multiple items in a table in one call.

ParameterTypeDefaultDescription
ttable t
...  Undefined number of arguments

string_split(string s, string delim, int limit)

Split the string s by a string delimiter delim.

ParameterTypeDefaultDescription
sstring The string to split
delimstring The delimiter
limitint0Maximum number of slices of string, values <= 1 are ignored..
Return
table: An array of at least one item (s if delim is not found)
Example

local t = string_split("Hello World!", " ")
 print(t[1]) --> Hello
 print(t[2]) --> World!

string_split_lines(string s)

Split the string s by lines, handle \r, \n and \r\n.

ParameterTypeDefaultDescription
sstring The string to split
Return
table: A table of at least one element (s if line separator is not found)

string_join(table list, string delimiter)

Concat the elements of table list, separated by the string delimiter.

ParameterTypeDefaultDescription
listtable list
delimiterstring delimiter
Return
string: string
Example

string_join({"Anna", "Bob", "Charlie", "Dolores"}, ", ")
 --> Anna, Bob, Charlie, Dolores

Issue