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.

  • 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:


join(delimiter, list)

Join a table into a string.

  • delimiter (String) – Inserts this string between each table element.
  • list (Table) – The table to join.
Return type:


is_in(needle, haystack)

Search table for given element.

  • needle (Any that supports == operator.) – The needle to find.
  • haystack (Table) – The haystack to search.
tablemerge(t1, t2)

Merge two tables together.

  • t1 (Table) – First table.
  • t2 (Table) – Second table.
Return type:


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.

  • 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.

  • 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.



Check if file exists on local filesystem.

Parameters:path (String) – Full path to file.
Return type:Boolean

Convert number value to hexadecimal string format.

Parameters:num (Number) – The number to convert.
Return type:String

Returns the current time in milliseconds precision. Unlike Lua builtin which only offers granularity in seconds.

Return type:Number

Returns milliseconds since arbitraty start point, doesn’t jump due to time changes.

Return type:Number