Module util
A collection of highly re-usable Lua utilities
Functions
template (source) | Generate a template-filling function based on a template string The template source can contain various template substitution items, indicated by the "$" character followed by a valid Lua variable name, e.g. |
Functions
- template (source)
-
Generate a template-filling function based on a template string
The template source can contain various template substitution items, indicated by the "$" character followed by a valid Lua variable name, e.g. "$foo", "$_x1", etc.
A template item can optionally be terminated using "{}", in order to distinguish the item name from plain text. E.g. "$foo{}plain" defines the item "foo" followed by the string "plain".
The returned function takes a Lua table as an argument. All substitution item names index corresponding fields in this table to find their data. If the data value is a table, util.conflat() is used to convert this to a string.
If a template item is preceded by a newline and whitespace, the newline and whitespace are repeated for all items substituted (via the argument to conflat()).
Parameters:
- source string template source
Returns:
-
function to apply a model