Module xLib
This is the core xLib class, containing a bunch of static helper methods .
Functions
unpack_args (...) | Turn varargs into a table |
is_song_available () | Detect if we have a renoise song: in rare cases it can briefly go missing, mostly while loading a song or creating a new document... |
match_table_key (t, key) | Match item(s) in an associative array (provide key) |
scale_value (value, in_min, in_max, out_min, out_max) | Number methods |
clamp_value (value, min_value, max_value) | clamp_value: ensure value is within min/max |
gcd (m, n) | greatest common divisor |
lcm (m, n) | least common multiplier (2 args) |
least_common (t) | find least common multiplier |
split (str, pat) | String methods |
trim (s) | remove trailing and leading whitespace from string. |
soft_wrap (str) | insert return code whenever we encounter dashes or spaces in a string TODO keep dashes, and allow a certain length per line |
detect_counter_in_str (str) | detect counter in string (used for incrementing, unique names) |
get_hex_digits (val) | find number of hex digits needed to represent a number (e.g. |
sanitize_string (str) | prepare a string so it can be stored in XML attributes (strip illegal characters instead of trying to fix them) |
stringify_table (t, prefix, suffix) | take a table and convert into strings - useful e.g. |
parse_str (str) | receives a string argument and turn it into a proper object or value |
round_value (num) | round_value (from http://lua-users.org/wiki/SimpleRound) |
float_compare (val1, val2, precision) | compare two numbers with variable precision |
fraction (val) | return the fractional part of a number |
table_compare (t1, t2) | quick'n'dirty table compare (values in first level only) |
serialize_object (obj) | try serializing a value or return "???" the result should be a valid, quotable string |
serialize_table (t, max_depth, longstring) | serialize table into string, with some formatting options |
Functions
- unpack_args (...)
-
Turn varargs into a table
Parameters:
- ...
- is_song_available ()
- Detect if we have a renoise song: in rare cases it can briefly go missing, mostly while loading a song or creating a new document...
- match_table_key (t, key)
-
Match item(s) in an associative array (provide key)
Parameters:
- t (table)
- key (string)
Returns:
-
table
- scale_value (value, in_min, in_max, out_min, out_max)
-
Number methods scale_value: scale a value to a range within a range
Parameters:
- value (number) the value we wish to scale
- in_min (number)
- in_max (number)
- out_min (number)
- out_max (number)
Returns:
-
number
- clamp_value (value, min_value, max_value)
-
clamp_value: ensure value is within min/max
Parameters:
- value (number)
- min_value (number)
- max_value (number)
Returns:
-
number
- gcd (m, n)
-
greatest common divisor
Parameters:
- m
- n
- lcm (m, n)
-
least common multiplier (2 args)
Parameters:
- m
- n
- least_common (t)
-
find least common multiplier
Parameters:
- t (table), use values in table as argument
- split (str, pat)
-
String methods split string - original script: http://lua-users.org/wiki/SplitJoin
Parameters:
- str (string)
- pat (string) pattern
Returns:
-
table
- trim (s)
-
remove trailing and leading whitespace from string.
http://en.wikipedia.org/wiki/Trim_(8programming)
Parameters:
- s (string)
Returns:
-
string
- soft_wrap (str)
-
insert return code whenever we encounter dashes or spaces in a string
TODO keep dashes, and allow a certain length per line
Parameters:
- str (string)
Returns:
-
string
- detect_counter_in_str (str)
-
detect counter in string (used for incrementing, unique names)
Parameters:
- str
- get_hex_digits (val)
-
find number of hex digits needed to represent a number (e.g. 255 = 2)
Parameters:
- val (int)
Returns:
-
int
- sanitize_string (str)
-
prepare a string so it can be stored in XML attributes
(strip illegal characters instead of trying to fix them)
Parameters:
- str (string)
Returns:
-
string
- stringify_table (t, prefix, suffix)
-
take a table and convert into strings - useful e.g. for viewbuilder popup
(if table is associative, will use values)
Parameters:
- t (table)
- prefix (string) insert before each entry
- suffix (string) insert after each entry
Returns:
-
table
- parse_str (str)
-
receives a string argument and turn it into a proper object or value
Parameters:
- str (string), e.g. "renoise.song().transport.keyboard_velocity"
Returns:
- value (can be nil)
- string, error message when failed
- round_value (num)
-
round_value (from http://lua-users.org/wiki/SimpleRound)
Parameters:
- num
- float_compare (val1, val2, precision)
-
compare two numbers with variable precision
Parameters:
- val1
- val2
- precision
Returns:
-
boolean
- fraction (val)
-
return the fractional part of a number
Parameters:
- val
Returns:
-
number
- table_compare (t1, t2)
-
quick'n'dirty table compare (values in first level only)
Parameters:
- t1 (table)
- t2 (table)
Returns:
-
boolean, true if identical
- serialize_object (obj)
-
try serializing a value or return "???"
the result should be a valid, quotable string
Parameters:
- obj , value or object
Returns:
-
string
- serialize_table (t, max_depth, longstring)
-
serialize table into string, with some formatting options
Parameters:
- t (table)
- max_depth (int), determine how many levels to process - optional
- longstring (boolean), use longstring format for multiline text
Returns:
-
table