Section Tables
Tables utility functions.
Summary
Return type | Function and summary |
---|---|
ArrayClear(table t) Optimization of clearing a table. | |
bool | ArrayContains(table tab, term) Does tab contains term? |
bool | isTable(obj) Returns true if obj is a table or a MyrScript object represented as a table such as Score or Target. |
string | string_join(table list, string delimiter) Concat the elements of table list, separated by the string delimiter. |
table | string_split(string s, string delim) Split the string s by a string delimiter delim. |
table | string_split_lines(string s) Split the string s by lines, handle \r, \n and \r\n. |
tdebug(tab) Return the structure of a table, Collection or Map for debugging to the console. |
Functions
isTable(obj)
Returns true if obj is a table or a MyrScript object represented as a table such as Score or Target.
Parameter | Type | Default | Description |
---|---|---|---|
obj |
- Return
- bool:
tdebug(tab)
Return the structure of a table, Collection or Map for debugging to the console.
Parameter | Type | Default | Description |
---|---|---|---|
tab |
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.
Parameter | Type | Default | Description |
---|---|---|---|
t | table | The table to clear. |
ArrayContains(table tab, term)
Does tab contains term?
Parameter | Type | Default | Description |
---|---|---|---|
tab | table | A table of numbers or strings | |
term | A number or a string to find in tab |
- Return
- bool: true, or ni (for false)
- Error
- if tab's items are not comparable with term
string_split(string s, string delim)
Split the string s by a string delimiter delim.
Parameter | Type | Default | Description |
---|---|---|---|
s | string | The string to split | |
delim | string | The delimiter |
- 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.
Parameter | Type | Default | Description |
---|---|---|---|
s | string | 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.
Parameter | Type | Default | Description |
---|---|---|---|
list | table | ||
delimiter | string |
- Return
- string:
- Example
string_join({"Anna", "Bob", "Charlie", "Dolores"}, ", ") --> Anna, Bob, Charlie, Dolores