Skip to content

Latest commit

 

History

History

inifile

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

inifile

inifile reads entries from a INI file.

Blank lines are ignores, and comments starting with a semi-colon are supported. Both keys and values are trimmed to remove surrounding spaces. Values are always returned as strings, no conversion is done.

Building

inifile is a pure Lua module.

Usage

inifile.iterate

Iterates over the entries of the INI file. Any object that implements a read function with the same semantics as the Lua io library can be used.

Example:

local inifile = require 'inifile'

-- Prints all <key, value> pairs in config.ini along with their section names and line numbers.
-- Errors are thrown with the error function.
local ini = assert(io.open('config.ini'))

for section, key, value, line in inifile.iterate(ini) do
    print(section, key, value, line)
end

inifile.load

Loads an INI file and returns all entries in a table. The table has section names as the keys with their values being the <key, value> pairs for the section.

Example:

local inifile = require 'inifile'

-- Loads all entries of config.ini and return them in a table
local ini = assert(inifile.load('config.ini'))

for section, data in pairs(ini) do
    for key, value in pairs(data) do
        print(section, key, value)
    end
end

Changelog

  • 1.0.1
    • Correctly trim out spaces from values
  • 1.0.0
    • First public release

License

MIT, enjoy.