Module irccd.parser
Config file parser.
This API provides basic support of .ini syntax based configurations files.
It provides support of multiple redefinition of sections, so it is
possible to have one or more section with the same name in a
file config.
Functions
-
new (path, tuning, commentChar)
-
Create a new Parser object.
This function does not open any file, you need to call open.
Parameters:
- path
the path
- tuning
optional table of tuning options
- commentChar
optional comment delimiter
Returns:
a Parser object
See also:
Tuning
-
DisableVerbosity
-
Disable the verbosity.
-
DisableRootSection
-
Forbid options on root.
-
DisableRedefinition
-
Disable multiple sections.
Class Parser
-
Parser:open ()
-
Open the file and read config.
This function will read and extract any section found in the file.
Returns:
-
true on success
-
error message if failed
-
Parser:findSections (name)
-
Iterator over all sections that matches name. Note that this function
will be relevant only if DisableRedefinition is not set. The iterator returns
a Section object.
Parameters:
Returns:
an iterator
Usage:
for s in p:findSections("socket") do
if s:hasOption("type") then
print("Type = " .. tostring(s:getOption("type")))
end
end
-
Parser:hasSection (name)
-
Checks for a section.
Checks if a specific section exists.
Parameters:
Returns:
true if exists
-
Parser:getSection (name)
-
Get a specific section.
Check if the parser has a specific section and return it, otherwise
return nil plus an error message.
Parameters:
Returns:
-
a Section object or nil
-
error message if not found
-
Parser:requireSection (name)
-
Get a specific section.
This returns a section but if the section
is not found it calls luaL_error, thus aborting the script.
Parameters:
Returns:
a Section
See also:
-
Parser:onLog (func)
-
Add a specific logging function.
This add a logging function for verbosity warnings. The function must have
the following signature:
function log(lineno, section, warning)
The parameters are:
- lineno: the current line number
- section: the current section
- warning: the message
Parameters:
Parser metamethods
The metamethods available for object Parser.
-
Parser:__tostring ()
-
Convert object to string.
Returns:
a string
Class Section
-
Section:hasOption (name)
-
Tells if the section has an option.
Check if the section contains a specific option.
Parameters:
Returns:
the value
-
Section:getOption (name)
-
Get an option value.
This function returns the value if found and nil plus an error
message in the other case.
Parameters:
Returns:
-
the option's value or nil
-
the error message
See also:
-
Section:getOptions ()
-
Get all options in a table.
This function will return a table with all options in a
key / value pair basis.
Returns:
a table
-
Section:requireOption (name)
-
Requires an option.
This returns a value but if the option
is not found it calls luaL_error, thus aborting the script.
Parameters:
Returns:
the option's value
See also:
Section metamethods
The metamethods available for object Section.
-
Section:__eq (other)
-
Test equality.
Parameters:
Returns:
true if they equals
-
Section:__le (other)
-
Test inferiority
Parameters:
Returns:
self <= other comparison
-
Section:__tostring ()
-
Convert object to string.
Returns:
a string