Inifile

Inifile is a lua library for parsing and writing ini files. It supports multiple backends, these are:

Data format

This section is about the format of the lua table corresponding to an ini file, it is not about the ini file format.

As ini files are made up of sections, with in them keys and values, the lua table is made how you’d expect:

  {
      section1 = {
          key1 = value1,
          key2 = value2,
      },
  
      section2 = {
          key3 = value3,
          key4 = value4,
      },
  }

Additionally, any table read in using inifile.parse has a metafield __inifile that stores comments and ordering present in the original file. This data can later be used by inifile.save to restore this to the best of the abilities.

Hopefully, no comments or ordering are lost parsing and saving an ini file again, but some data simply can’t be stored with the current architecture. However, most information should be preserved, and after the first “copy”, any subsequent “copies” should be equal (even byte-for-byte).

Functions

table = inifile.parse(name, backend = <default>)

This function takes a filename (or data string, depending on the backend), and parses the corresponding ini file, producing a table. The structure of this table is defined in the Data format section.

result = inifile.save(name, table, backend = <default>)

This function takes a table in the right format (see Data formats) and writes it to the corresponding file.
Note that the memory backend is the only one that produces a result (and the filename is ignored).