Module base
Adds to the existing global functions
Functions
_G.assert (v, f, ...) | Extend to allow formatted arguments. |
_G.bind (f, ...) | Partially apply a function. |
_G.collect (i, ...) | Collect the results of an iterator. |
_G.compose (..., f1...fn) | Compose functions. |
_G.curry (f, n) | Curry a function. |
_G.die (...) | Die with error. |
_G.eval (s) | Evaluate a string. |
_G.filter (p, i, ...) | Filter an iterator with a predicate. |
_G.fold (f, d, i, ...) | Fold a binary function into an iterator. |
_G.id (...) | Identity function. |
_G.ileaves (tr) | Tree iterator which returns just numbered leaves, in order. |
_G.inodes (tr) | Tree iterator over numbered nodes, in order. |
_G.leaves (tr) | Tree iterator which returns just leaves. |
_G.map (f, i, ...) | Map a function over an iterator. |
_G.memoize (fn) | Memoize a function, by wrapping it in a functable. |
_G.metamethod (x, n) | Return given metamethod, if any, or nil. |
_G.nodes (tr) | Tree iterator. |
_G.pack (...) | Turn a tuple into a list. |
_G.pickle (x) | Convert a value to a string. |
_G.prettytostring (t, indent, spacing) | Pretty-print a table. |
_G.render (x, open, close, elem, pair, sep, roots) | Turn tables into strings with recursion detection. |
_G.ripairs (t) | An iterator like ipairs, but in reverse. |
_G.tostring (x) | Extend tostring to work better on tables. |
_G.totable (x) | Turn an object into a table according to __totable metamethod. |
_G.warn (...) | Give warning with the name of program and file (if any). |
render_CloseRenderer (t) | |
render_ElementRenderer (e) | |
render_OpenRenderer (t) | |
render_PairRenderer N.B. the function should not try to render i and v, or treat them recursively. (t, i, v, is, vs) | |
render_SeparatorRenderer (t, i, v, j, w) | |
tree_Iterator (it, tr, n) |
Tables
_G.op | Functional forms of infix operators. |
Functions
- _G.assert (v, f, ...)
-
Extend to allow formatted arguments.
Parameters
- v: value to assert
- f: format
- ...: arguments to format
Return value:
value - _G.bind (f, ...)
-
Partially apply a function.
Parameters
- f: function to apply partially
- ...: arguments to bind
Return value:
function with ai already bound - _G.collect (i, ...)
-
Collect the results of an iterator.
Parameters
- i: iterator
- ...:
Return value:
results of running the iterator on its arguments - _G.compose (..., f1...fn)
-
Compose functions.
Parameters
- ...:
- f1...fn: functions to compose
Return value:
composition of f1 ... fn - _G.curry (f, n)
-
Curry a function.
Parameters
- f: function to curry
- n: number of arguments
Return value:
curried version of f - _G.die (...)
-
Die with error.
Parameters
- ...: arguments for format
- _G.eval (s)
-
Evaluate a string.
Parameters
- s: string
Return value:
value of string - _G.filter (p, i, ...)
-
Filter an iterator with a predicate.
Parameters
- p: predicate
- i: iterator
- ...:
Return value:
result table containing elements e for which p (e) - _G.fold (f, d, i, ...)
-
Fold a binary function into an iterator.
Parameters
- f: function
- d: initial first argument
- i: iterator
- ...:
Return value:
result - _G.id (...)
-
Identity function.
Parameters
- ...:
Return value:
the arguments passed to the function - _G.ileaves (tr)
-
Tree iterator which returns just numbered leaves, in order.
Parameters
- tr: tree to iterate over
Return values:
- iterator function
- the tree, as above
- _G.inodes (tr)
-
Tree iterator over numbered nodes, in order.
Parameters
- tr: tree to iterate over
Return values:
- iterator function
- the tree, as above
See also:
- _G.leaves (tr)
-
Tree iterator which returns just leaves.
Parameters
- tr: tree to iterate over
Return values:
- iterator function
- the tree, as above
- _G.map (f, i, ...)
-
Map a function over an iterator.
Parameters
- f: function
- i: iterator
- ...:
Return value:
result table - _G.memoize (fn)
-
Memoize a function, by wrapping it in a functable.
Parameters
- fn: function that returns a single result
Return value:
memoized function - _G.metamethod (x, n)
-
Return given metamethod, if any, or nil.
Parameters
- x: object to get metamethod of
- n: name of metamethod to get
Return value:
metamethod function or nil if no metamethod or not a function - _G.nodes (tr)
-
Tree iterator.
Parameters
- tr: tree to iterate over
Return values:
- iterator function
- the tree, as above
See also:
- _G.pack (...)
-
Turn a tuple into a list.
Parameters
- ...: tuple
Return value:
list - _G.pickle (x)
-
Convert a value to a string. The string can be passed to dostring to retrieve the value.
TODO: Make it work for recursive tables.Parameters
- x: object to pickle
Return value:
string such that eval (s) is the same value as x - _G.prettytostring (t, indent, spacing)
-
Pretty-print a table.
Parameters
- t: table to print
- indent: indent between levels ["\t"]
- spacing: space before every line
Return value:
pretty-printed string - _G.render (x, open, close, elem, pair, sep, roots)
-
Turn tables into strings with recursion detection. N.B. Functions calling render should not recurse, or recursion detection will not work.
Parameters
- x: object to convert to string
- open: open table renderer
- close: close table renderer
- elem: element renderer
- pair: pair renderer
- sep: separator renderer
- roots:
Return value:
string representationSee also:
- _G.ripairs (t)
-
An iterator like ipairs, but in reverse.
Parameters
- t: table to iterate over
Return values:
- iterator function
- the table, as above
- #t + 1
- _G.tostring (x)
-
Extend
tostring
to work better on tables.Parameters
- x: object to convert to string
Return value:
string representation - _G.totable (x)
-
Turn an object into a table according to __totable metamethod.
Parameters
- x: object to turn into a table
Return value:
table or nil - _G.warn (...)
-
Give warning with the name of program and file (if any).
Parameters
- ...: arguments for format
- render_CloseRenderer (t)
-
Parameters
- t: table
Return value:
close table string - render_ElementRenderer (e)
-
Parameters
- e: element
Return value:
element string - render_OpenRenderer (t)
-
Parameters
- t: table
Return value:
open table string - render_PairRenderer N.B. the function should not try to render i and v, or treat them recursively. (t, i, v, is, vs)
-
Parameters
- t: table
- i: index
- v: value
- is: index string
- vs: value string
Return value:
element string - render_SeparatorRenderer (t, i, v, j, w)
-
Parameters
- t: table
- i: preceding index (nil on first call)
- v: preceding value (nil on first call)
- j: following index (nil on last call)
- w: following value (nil on last call)
Return value:
separator string - tree_Iterator (it, tr, n)
-
Parameters
- it:
- tr:
- n: current node
Return values:
- type ("leaf", "branch" (pre-order) or "join" (post-order))
- path to node ({i1...ik})
- node