lua_util
This module contains utility functions for working with Lua and/or Rspamd
Functions:
Function | Description |
---|---|
lua_util.str_split(text, delimiter) |
Splits text into a numeric table by delimiter. |
lua_util.str_trim(text) |
Returns a string with no trailing and leading spaces. |
lua_util.str_startswith(text, prefix) |
No description |
lua_util.str_endswith(text, suffix) |
No description |
lua_util.round(number, decimalPlaces) |
Round number to fixed number of decimal points. |
lua_util.template(text, replacements) |
Replaces values in a text template. |
lua_util.jinja_template(text, env[, skip_global_env][, is_orig][, custom_filters]) |
Replaces values in a text template according to jinja2 syntax. |
lua_util.jinja_file(filename, env[, skip_global_env][, is_orig][, custom_filters]) |
Replaces values in a text template according to jinja2 syntax. |
lua_util.unpack(table) |
Converts numeric table to varargs. |
lua_util.flatten(table) |
Flatten underlying tables in a single table. |
lua_util.spairs(table) |
Like pairs but keys are sorted lexicographically. |
lua_util.disable_module(modname) |
Checks experimental plugins state and disable if needed. |
lua_util.list_to_hash(list) |
Converts numerically-indexed table to table indexed by values. |
lua_util.nkeys(table|gen, param, state) |
Returns number of keys in a table (i.e. |
lua_util.parse_time_interval(str) |
Parses human readable time interval. |
lua_util.dehumanize_number(str) |
Parses human readable number. |
lua_util.table_cmp(t1, t2) |
Compare two tables deeply. |
lua_util.table_merge(t1, t2) |
Merge two tables. |
lua_util.table_cmp(task, name, value, stop_chars) |
Performs header folding. |
lua_util.override_defaults(defaults, override) |
Overrides values from defaults with override. |
lua_util.filter_specific_urls(urls, params) |
params. |
lua_util.extract_specific_urls(params) |
params. |
lua_util.deepcopy(table) |
params. |
lua_util.deepsort(table) |
params. |
lua_util.shallowcopy(tbl) |
Performs shallow (and fast) copy of a table or another Lua type. |
lua_util.debugm(module, [log_object], format, ...) |
Performs fast debug log for a specific module. |
lua_util.add_debug_alias(mod, alias) |
Add debugging alias so logging to alias will be treated as logging to mod . |
The module lua_util
defines the following functions.
lua_util.str_split(text, delimiter)
Splits text into a numeric table by delimiter
Parameters:
text {string}
: delimited textdelimiter {string}
: the delimiterReturns:
{table}
: numeric table containing string partsBack to module description.
lua_util.str_trim(text)
Returns a string with no trailing and leading spaces
Parameters:
text {string}
: input textReturns:
{string}
: string with no trailing and leading spacesBack to module description.
lua_util.str_startswith(text, prefix)
Parameters:
text {string}
: no descriptionprefix {string}
: no descriptionReturns:
{boolean}
: true if text starts with the specified prefix, false otherwiseBack to module description.
lua_util.str_endswith(text, suffix)
Parameters:
text {string}
: no descriptionsuffix {string}
: no descriptionReturns:
{boolean}
: true if text ends with the specified suffix, false otherwiseBack to module description.
lua_util.round(number, decimalPlaces)
Round number to fixed number of decimal points
Parameters:
number {number}
: number to rounddecimalPlaces {number}
: number of decimal pointsReturns:
{number}
: rounded numberBack to module description.
lua_util.template(text, replacements)
Replaces values in a text template
Variable names can contain letters, numbers and underscores, are prefixed with $
and may or not use curly braces.
Parameters:
text {string}
: text containing variablesreplacements {table}
: key/value pairs for replacementsReturns:
{string}
: string containing replaced valuesBack to module description.
lua_util.jinja_template(text, env[, skip_global_env][, is_orig][, custom_filters])
Replaces values in a text template according to jinja2 syntax
Parameters:
text {string}
: text containing variablesreplacements {table}
: key/value pairs for replacementsskip_global_env {boolean}
: don’t export Rspamd superglobalsis_orig {boolean}
: use the original lupa configuration with {{
for variablescustom_filters {table}
: custom filters to use (or nil if not needed)Returns:
{string}
: string containing replaced valuesBack to module description.
lua_util.jinja_file(filename, env[, skip_global_env][, is_orig][, custom_filters])
Replaces values in a text template according to jinja2 syntax
Parameters:
filename {string}
: name of file to expandreplacements {table}
: key/value pairs for replacementsskip_global_env {boolean}
: don’t export Rspamd superglobalsis_orig {boolean}
: use the original lupa configuration with {{
for variablescustom_filters {table}
: custom filters to use (or nil if not needed)Returns:
{string}
: string containing replaced valuesBack to module description.
lua_util.unpack(table)
Converts numeric table to varargs
This is unpack
on Lua 5.1/5.2/LuaJIT and table.unpack
on Lua 5.3
Parameters:
table {table}
: numerically indexed table to unpackReturns:
{varargs}
: unpacked table elementsBack to module description.
lua_util.flatten(table)
Flatten underlying tables in a single table
Parameters:
table {table}
: table of tablesReturns:
{table}
: flattened tableBack to module description.
lua_util.spairs(table)
Like pairs
but keys are sorted lexicographically
Parameters:
table {table}
: table containing key/value pairsReturns:
{function}
: generator function returning key/value pairsBack to module description.
lua_util.disable_module(modname)
Checks experimental plugins state and disable if needed
Parameters:
modname {string}
: name of plugin to checkReturns:
{boolean}
: true if plugin should be enabled, false otherwiseBack to module description.
lua_util.list_to_hash(list)
Converts numerically-indexed table to table indexed by values
Parameters:
list {table}
: numerically-indexed table or string, which is treated as a one-element listReturns:
{table}
: table indexed by valuesBack to module description.
lua_util.nkeys(table|gen, param, state)
Returns number of keys in a table (i.e. from both the array and hash parts combined)
Parameters:
list {table}
: numerically-indexed table or string, which is treated as a one-element listReturns:
{number}
: number of keysBack to module description.
lua_util.parse_time_interval(str)
Parses human readable time interval Accepts ‘s’ for seconds, ‘m’ for minutes, ‘h’ for hours, ‘d’ for days, ‘w’ for weeks, ‘y’ for years
Parameters:
str {string}
: input stringReturns:
{number|nil}
: parsed interval as seconds (might be fractional)Back to module description.
lua_util.dehumanize_number(str)
Parses human readable number
Accepts ‘k’ for thousands, ‘m’ for millions, ‘g’ for billions, ‘b’ suffix for 1024 multiplier,
e.g. 10mb
equal to 10 * 1024 * 1024
Parameters:
str {string}
: input stringReturns:
{number|nil}
: parsed numberBack to module description.
lua_util.table_cmp(t1, t2)
Compare two tables deeply
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.table_merge(t1, t2)
Merge two tables
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.table_cmp(task, name, value, stop_chars)
Performs header folding
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.override_defaults(defaults, override)
Overrides values from defaults with override
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.filter_specific_urls(urls, params)
params: {
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.extract_specific_urls(params)
params: {
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.deepcopy(table)
params: {
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.deepsort(table)
params: {
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.shallowcopy(tbl)
Performs shallow (and fast) copy of a table or another Lua type
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.debugm(module, [log_object], format, ...)
Performs fast debug log for a specific module
Parameters:
No parameters
Returns:
No return
Back to module description.
lua_util.add_debug_alias(mod, alias)
Add debugging alias so logging to alias
will be treated as logging to mod
Parameters:
No parameters
Returns:
No return
Back to module description.
Back to top.