turbo.util Common utilities¶
The util namespace contains various convinience functions that fits no where else. As Lua is fairly naked as standard. Just the way we like it.
Table tools¶
-
strsplit
(str, sep, max, pattern)¶ Split a string into a table on given seperator. This function extends the standard string library with new functionality.
Parameters: - str (String) – String to split
- sep (String) – String that seperate elements.
- max (Number) – Max elements to split
- pattern (Boolean) – Separator should be treated as a Lua pattern. Slower.
Return type: Table
-
join
(delimiter, list)¶ Join a table into a string.
Parameters: - delimiter (String) – Inserts this string between each table element.
- list (Table) – The table to join.
Return type: String
-
is_in
(needle, haystack)¶ Search table for given element.
Parameters: - needle (Any that supports == operator.) – The needle to find.
- haystack (Table) – The haystack to search.
-
tablemerge
(t1, t2)¶ Merge two tables together.
Parameters: - t1 (Table) – First table.
- t2 (Table) – Second table.
Return type: Table
Low level¶
-
mem_dump
(ptr, sz)¶ Dump memory region to stdout, from ptr to given size. Usefull for debugging Luajit FFI. Notice! This can and will cause a SIGSEGV if not being used on valid pointers.
Parameters: - ptr (cdata) – A cdata pointer (from FFI)
- sz (Number) – Length to dump contents for.
-
TBM
(x, m, y, n)¶ Turbo Booyer-Moore memory search algorithm. Search through arbitrary memory and find first occurence of given byte sequence. Effective when looking for large needles in a large haystack.
Parameters: - x (char*) – Needle memory pointer.
- m (int) – Needle size.
- y (char*) – Haystack memory pointer.
- n (int) – Haystack size.
Return type: First occurence of byte sequence in y defined in x or nil if not found.
Misc¶
-
file_exists
(name)¶ Check if file exists on local filesystem.
Parameters: path (String) – Full path to file. Return type: Boolean
-
hex
(num)¶ Convert number value to hexadecimal string format.
Parameters: num (Number) – The number to convert. Return type: String
-
gettimeofday
()¶ Returns the current time in milliseconds precision. Unlike Lua builtin which only offers granularity in seconds.
Return type: Number
-
gettimemonotonic
()¶ Returns milliseconds since arbitraty start point, doesn’t jump due to time changes.
Return type: Number