Module util
random utils
Functions
exists (name) | check whether a file exists |
file_exists (name) | norns compat |
time () | get system time in fractional seconds |
scandir (directory) | scan directory, return file list. |
file_size (path) | query file size. |
make_dir (path) | make directory (with parents as needed). |
os_capture (cmd, raw) | execute os command, capture output. |
string_starts (s, start) | string begins with. |
trim_string_to_width (s, width) | trim string to a display width |
clamp (n, min, max) | clamp values to min max. |
linexp (slo, shi, dlo, dhi, f) | convert a linear range to an exponential range |
linlin (slo, shi, dlo, dhi, f) | map a linear range to another linear range. |
explin (slo, shi, dlo, dhi, f) | convert an exponential range to a linear range. |
expexp (slo, shi, dlo, dhi, f) | map an exponential range to another exponential range. |
round (number, quant) | round a number with optional quantization |
clear_screen () | clear the terminal window |
os_capture (cmd[, raw]) | execute OS command |
acronym (name) | convert string to acronym |
degs_to_rads (degrees) | convert degrees to radians |
rads_to_degs (radians) | convert radians to degrees |
wrap (n, min, max) | wrap a integer to a positive min/max range |
wrap_max (n, min, max) | wrap an integer to a positive min/max range but clamp the min |
version_parse (v) | parse a version string into a list of ints |
version_compare (v1, v2) | compare versions v1 and v2 |
Functions
- exists (name)
-
check whether a file exists
Parameters:
- name string filename
Returns:
-
bool
true if the file exists
- file_exists (name)
-
norns compat
Parameters:
- name
- time ()
-
get system time in fractional seconds
Returns:
-
time
- scandir (directory)
-
scan directory, return file list.
Parameters:
- directory string path to directory
Returns:
- file_size (path)
-
query file size.
Parameters:
- path string filepath
Returns:
-
number
filesize in bytes
- make_dir (path)
-
make directory (with parents as needed).
Parameters:
- path string
- os_capture (cmd, raw)
-
execute os command, capture output.
Parameters:
- cmd string command
- raw raw output (omit for scrubbed)
Returns:
-
output
- string_starts (s, start)
-
string begins with.
Parameters:
Returns:
-
boolean
true or false
- trim_string_to_width (s, width)
-
trim string to a display width
Parameters:
- s string string to trim
- width number maximum width
Returns:
-
string
trimmed string
- clamp (n, min, max)
-
clamp values to min max.
Parameters:
- n number value
- min number minimum
- max number maximum
Returns:
-
number
clamped value
- linexp (slo, shi, dlo, dhi, f)
-
convert a linear range to an exponential range
Parameters:
- slo number lower limit of input range
- shi number upper limit of input range
- dlo number lower limit of output range (must be non-zero and of the same sign as dhi)
- dhi number upper limit of output range (must be non-zero and of the same sign as dlo)
- f number input to convert
Returns:
-
number
- linlin (slo, shi, dlo, dhi, f)
-
map a linear range to another linear range.
Parameters:
- slo number lower limit of input range
- shi number upper limit of input range
- dlo number lower limit of output range
- dhi number upper limit of output range
- f number input to convert
Returns:
-
number
- explin (slo, shi, dlo, dhi, f)
-
convert an exponential range to a linear range.
Parameters:
- slo number lower limit of input range (must be non-zero and of the same sign as shi)
- shi number upper limit of input range (must be non-zero and of the same sign as slo)
- dlo number lower limit of output range
- dhi number upper limit of output range
- f number input to convert
Returns:
-
number
- expexp (slo, shi, dlo, dhi, f)
-
map an exponential range to another exponential range.
Parameters:
- slo number lower limit of input range (must be non-zero and of the same sign as shi)
- shi number upper limit of input range (must be non-zero and of the same sign as slo)
- dlo number lower limit of output range (must be non-zero and of the same sign as dhi)
- dhi number upper limit of output range (must be non-zero and of the same sign as dlo)
- f number input to convert
Returns:
-
number
- round (number, quant)
-
round a number with optional quantization
Parameters:
- number number a number
- quant number quantization
- clear_screen ()
- clear the terminal window
- os_capture (cmd[, raw])
-
execute OS command
Parameters:
- cmd string command to execute
- raw bool flag whether to clean up output (optional)
Returns:
-
string
output from executing the command
- acronym (name)
-
convert string to acronym
Parameters:
- name string
Returns:
-
string
acronym
- degs_to_rads (degrees)
-
convert degrees to radians
Parameters:
- degrees number
Returns:
-
number
radians
- rads_to_degs (radians)
-
convert radians to degrees
Parameters:
- radians number
Returns:
-
number
degrees
- wrap (n, min, max)
-
wrap a integer to a positive min/max range
Parameters:
- n integer
- min integer
- max integer
Returns:
-
integer
cycled value
- wrap_max (n, min, max)
-
wrap an integer to a positive min/max range but clamp the min
Parameters:
- n integer
- min integer
- max integer
Returns:
-
integer
cycled value
- version_parse (v)
-
parse a version string into a list of ints
Parameters:
- v string
Returns:
- version_compare (v1, v2)
-
compare versions v1 and v2
Parameters:
Returns:
-
integer