Module 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.
Example:
###Brief content:
Functions:
Methods:
Functions
The module ucl defines the following functions.
Function 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:
scalar values are directly presented by lua objects
userdata values are converted to lua function objects using
LUA_REGISTRYINDEX, this can be used to pass functions from lua to c and vice-versaarrays are converted to lua tables with numeric indices suitable for
ipairsiterationsobjects are converted to lua tables with string indices
Parameters:
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}:1if an object is pushed to lua
Back to module description.
Function 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 asconfigyaml- embedded yaml
If var contains function, they are called during output formatting and if they return string value, then this value is used for ouptut.
Parameters:
var {variant}: any sort of lua variable (if userdata then metafield__to_uclis searched for output)format {string}: any available format
Returns:
{string}: string representation ofvarin the specificformat.
Example:
Back to module description.
Methods
The module ucl defines the following methods.
Method parser:parse_file(name)
Parse UCL object from file.
Parameters:
name {string}: filename to parse
Returns:
{bool[, string]}: if res istruethen file has been parsed successfully, otherwise an error string is also returned
Example:
Back to module description.
Method parser:parse_string(input)
Parse UCL object from file.
Parameters:
input {string}: string to parse
Returns:
{bool[, string]}: if res istruethen file has been parsed successfully, otherwise an error string is also returned
Back to module description.
Method parser:get_object()
Get top object from parser and export it to lua representation.
Parameters:
Returns:
{variant or nil}: ucl object as lua native variable
Back to module description.
Back to top.