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.

Tuning

DisableVerbosity Disable the verbosity.
DisableRootSection Forbid options on root.
DisableRedefinition Disable multiple sections.

Class Parser

Parser:open () Open the file and read config.
Parser:findSections (name) Iterator over all sections that matches name.
Parser:hasSection (name) Checks for a section.
Parser:getSection (name) Get a specific section.
Parser:requireSection (name) Get a specific section.
Parser:onLog (func) Add a specific logging function.

Parser metamethods

Parser:__tostring () Convert object to string.

Class Section

Section:hasOption (name) Tells if the section has an option.
Section:getOption (name) Get an option value.
Section:getOptions () Get all options in a table.
Section:requireOption (name) Requires an option.

Section metamethods

Section:__eq (other) Test equality.
Section:__le (other) Test inferiority
Section:__tostring () Convert object to string.


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:

  1. true on success
  2. 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:

  • name the sections name

Returns:

    an iterator

Usage:

     -- Find all sections named "socket"
     for s in p:findSections("socket") do
     	-- Play with s as a Section object
     	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:

  • name

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:

  • name the section name

Returns:

  1. a Section object or nil
  2. 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:

  • name the section name

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:

  • func the function to use

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:

  • name the option's name

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:

  • name the option name

Returns:

  1. the option's value or nil
  2. 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:

  • name the option name

Returns:

    the option's value

See also:

Section metamethods

The metamethods available for object Section.
Section:__eq (other)
Test equality.

Parameters:

  • other the other section

Returns:

    true if they equals
Section:__le (other)
Test inferiority

Parameters:

  • other the other section

Returns:

    self <= other comparison
Section:__tostring ()
Convert object to string.

Returns:

    a string
generated by LDoc 1.4.0