Module pl.config

Reads configuration files into a Lua table.

Understands INI files, classic Unix config files, and simple delimited columns of values.

    # test.config
    # Read timeout in seconds
    read.timeout=10
    # Write timeout in seconds
    write.timeout=5
    #acceptable ports
    ports = 1002,1003,1004

        -- readconfig.lua
    require 'pl'
    local t = config.read 'test.config'
    print(pretty.write(t))
    
    ### output #####
   {
      ports = {
        1002,
        1003,
        1004
      },
      write_timeout = 5,
      read_timeout = 10
    }    
 
See the Guide for further discussion

Functions

lines (file) like io.lines(), but allows for lines to be continued with '\'.
read (file, cnfg) read a configuration file into a table


Functions

lines (file)
like io.lines(), but allows for lines to be continued with '\'.

Parameters:

  • file: a file-like object (anything where read() returns the next line) or a filename. Defaults to stardard input.

Returns:

    an iterator over the lines
read (file, cnfg)
read a configuration file into a table

Parameters:

  • file: either a file-like object or a string, which must be a filename
  • cnfg: a configuration table that may contain these fields:
    • variablilize make names into valid Lua identifiers (default true)
    • convert_numbers try to convert values into numbers (default true)
    • trim_space ensure that there is no starting or trailing whitespace with values (default true)
    • list_delim delimiter to use when separating columns (default ',')

Returns:

    nil,error_msg in case of an error, otherwise a table containing items