Module util
Various helper functions
log(x, base) |
logarithm for an arbirary base |
log2(x) |
logarithm for base 2 |
log10(x) |
logarithm for base 10 |
clamp(min, max, val) |
Clamp a value between a minimum and a maximum |
set(entries) |
Turn a array style table into a {[value] = true} mapping table |
a2a_map(fn, items) |
Array to Array map. |
i2a_map(fn, iter) |
Iterator to Array map. |
a2i_map(fn, items) |
Array to Iterator map. |
i2i_map(fn, iter) |
Iterator to Iterator map. |
map(fn, items) |
Call a function on each item of an array or iterator. |
imap(fn, items) |
Calls a function on each item of an array or iterator. |
range(start, stop[, step=1]) |
Generate a table of numbers from start to stop with step size step,
like for i = start, stop, step do ... |
avg(arr) |
Calculate the average of a table of numbers. |
shuffle(array) |
Shuffle a table in-place using Fisher-Yates shuffle. |
-
class([parent])
-
simple class creation helper
Parameters:
- parent
parent class
(optional)
-
memoize([delay], fn)
-
Wrap a function to store its results for fast access via identical arguments.
Parameters:
- delay
int
number of updates that should pass before
data is cleared; use 0/false/nil to never clear
(optional)
- fn
func
function to be memoized; should only take stringable
arguments and return a non-nil value
-
reset_data(update_count)
-
Clear outdated data gathered via util.memoize.
Call this once per update cycle.
Parameters:
- update_count
int
conky's $update_count
Circular queue implementation.
Adding new values causes old values to disappear.
Use # to get length, ipairs to iterate, [] to access individual values.
-
CycleQueue:init(items)
-
Parameters:
- items
int or table
length of queue or array of initial items
-
CycleQueue:put(item)
-
Add a value, causing the oldest value to disappear.
Parameters:
-
CycleQueue:__len()
-
Get the length of this Queue as specified in CycleQueue:init.
Implements # for Lua 5.2+
-
CycleQueue:__index(idx)
-
Access individual items by 1-based index.
Implements ...[idx] access for Lua 5.2+
Parameters:
Returns:
item at index idx (or a named property of this instance)
-
CycleQueue:__ipairs()
-
Iterate items and indices (starting at 1).
Implements ipairs(...) for Lua 5.2+
Returns:
func,table,int
-
log(x, base)
-
logarithm for an arbirary base
Parameters:
-
log2(x)
-
logarithm for base 2
Parameters:
-
log10(x)
-
logarithm for base 10
Parameters:
-
clamp(min, max, val)
-
Clamp a value between a minimum and a maximum
Parameters:
- min
number
minimum value returned
- max
number
maximum value returned
- val
number
target value
Returns:
number
-
set(entries)
-
Turn a array style table into a {[value] = true} mapping table
Parameters:
Returns:
table
{key = true} mapping
-
a2a_map(fn, items)
-
Array to Array map.
Calls a function on each item of a table. Collect the results in a table.
Parameters:
- fn
func
should take one argument and return one result
- items
tab
array
Returns:
table
array of results
-
i2a_map(fn, iter)
-
Iterator to Array map.
Calls a function on each item of an iterator. Collect the results in a table.
Parameters:
- fn
func
should take one argument and return one result
- iter
func
iterator
Returns:
table
array of results
-
a2i_map(fn, items)
-
Array to Iterator map.
Calls a function on each item of a table. Iterate the results.
Parameters:
- fn
func
should take one argument and return one result
- items
tab
array
Returns:
func
results iterator
-
i2i_map(fn, iter)
-
Iterator to Iterator map.
Calls a function on each item of an iterator. Iterate the results.
Parameters:
- fn
func
should take one argument and return one result
- iter
func
iterator
Returns:
func
results iterator
-
map(fn, items)
-
Call a function on each item of an array or iterator.
Collect the results in a table.
Parameters:
- fn
func
should take one argument and return one result
- items
table or func
Returns:
table
array of results
-
imap(fn, items)
-
Calls a function on each item of an array or iterator.
Iterate the results.
Parameters:
- fn
func
should take one argument and return one result
- items
table or func
Returns:
func
results iterator
-
range(start, stop[, step=1])
-
Generate a table of numbers from start to stop with step size step,
like for i = start, stop, step do ...
Parameters:
- start
number
- stop
number
- step
number
(default 1)
Returns:
{number,...}
-
avg(arr)
-
Calculate the average of a table of numbers.
Parameters:
Returns:
number
-
shuffle(array)
-
Shuffle a table in-place using Fisher-Yates shuffle.
Parameters: