ucl
This lua module allows to parse objects from strings and to store data into
ucl objects. It uses libucl
C library to parse and manipulate with ucl objects.
Functions:
Function | Description |
---|---|
ucl_object_push_lua(L, obj, allow_array) |
This is a C function to push UCL object as lua variable. |
ucl.to_format(var, format) |
Converts lua variable var to the specified format . |
Methods:
Method | Description |
---|---|
parser:parse_file(name) |
Parse UCL object from file. |
parser:register_variable(name, value) |
Register parser variable. |
parser:register_variables(vars) |
Register parser variables. |
parser:parse_string(input) |
Parse UCL object from file. |
parser:parse_text(input) |
Parse UCL object from text object (Rspamd specific). |
parser:get_object() |
Get top object from parser and export it to lua representation. |
parser:get_object_wrapped() |
Get top object from parser and export it to userdata object without. |
parser:validate(schema) |
Validates the top object in the parser against schema. |
object:unwrap() |
Unwraps opaque ucl object to the native lua object (performing copying). |
object:tostring(type) |
Unwraps opaque ucl object to string (json by default). |
object:validate(schema[, path[, ext_refs]]) |
Validates the given ucl object using schema object represented as another. |
The module ucl
defines the following functions.
ucl_object_push_lua(L, obj, allow_array)
This is a C
function to push UCL
object as lua variable. This function
converts obj
to lua representation using the following conversions:
LUA_REGISTRYINDEX
,
this can be used to pass functions from lua to c and vice-versaipairs
iterationsParameters:
L {lua_State}
: lua state pointerobj {ucl_object_t}
: object to pushallow_array {bool}
: expand implicit arrays (should be true for all but partial arrays)Returns:
{int}
: 1
if an object is pushed to luaBack to module description.
ucl.to_format(var, format)
Converts lua variable var
to the specified format
. Formats supported are:
json
- fine printed jsonjson-compact
- compacted jsonconfig
- fine printed configurationucl
- same as config
yaml
- embedded yamlIf var
contains function, they are called during output formatting and if
they return string value, then this value is used for output.
Parameters:
var {variant}
: any sort of lua variable (if userdata then metafield __to_ucl
is searched for output)format {string}
: any available formatReturns:
{string}
: string representation of var
in the specific format
.Back to module description.
The module ucl
defines the following methods.
parser:parse_file(name)
Parse UCL object from file.
Parameters:
name {string}
: filename to parseReturns:
{bool[, string]}
: if res is true
then file has been parsed successfully, otherwise an error string is also returnedBack to module description.
parser:register_variable(name, value)
Register parser variable
Parameters:
name {string}
: name of variablevalue {string}
: value of variableReturns:
{bool}
: successBack to module description.
parser:register_variables(vars)
Register parser variables
Parameters:
vars {table}
: names/values of variablesReturns:
{bool}
: successBack to module description.
parser:parse_string(input)
Parse UCL object from file.
Parameters:
input {string}
: string to parseReturns:
{bool[, string]}
: if res is true
then file has been parsed successfully, otherwise an error string is also returnedBack to module description.
parser:parse_text(input)
Parse UCL object from text object (Rspamd specific).
Parameters:
input {rspamd_text}
: text to parseReturns:
{bool[, string]}
: if res is true
then file has been parsed successfully, otherwise an error string is also returnedBack to module description.
parser:get_object()
Get top object from parser and export it to lua representation.
Parameters:
No parameters
Returns:
{variant or nil}
: ucl object as lua native variableBack to module description.
parser:get_object_wrapped()
Get top object from parser and export it to userdata object without unwrapping to lua.
Parameters:
No parameters
Returns:
{ucl.object or nil}
: ucl object wrapped variableBack to module description.
parser:validate(schema)
Validates the top object in the parser against schema. Schema might be another object or a string that represents file to load schema from.
Parameters:
schema {string/table}
: input schemaReturns:
{result,err}
: two values: boolean result and the corresponding errorBack to module description.
object:unwrap()
Unwraps opaque ucl object to the native lua object (performing copying)
Parameters:
No parameters
Returns:
{variant}
: any lua objectBack to module description.
object:tostring(type)
Unwraps opaque ucl object to string (json by default). Optionally you can specify output format:
json
- fine printed jsonjson-compact
- compacted jsonconfig
- fine printed configurationucl
- same as config
yaml
- embedded yamlParameters:
type {string}
: optionalReturns:
{string}
: string representation of the opaque ucl objectBack to module description.
object:validate(schema[, path[, ext_refs]])
Validates the given ucl object using schema object represented as another
opaque ucl object. You can also specify path in the form #/path/def
to
specify the specific schema element to perform validation.
error, if ext_refs
are also specified, then they are returned as opaque
ucl object as {result,err,ext_refs}
Parameters:
schema {ucl.object}
: schema objectpath {string}
: optional path for validation procedureReturns:
{result,err}
: two values: boolean result and the correspondingBack to module description.
Back to top.