lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, Sep 27, 2016 at 10:41 PM, Russell Haley <> wrote:

> So this parses SPACE separated lines. I'm not familiar enough with
> line matching patterns or lpeg to be effective

> I've also considered just serializing/deserializing lua tables, but at
> some point I have to support reading and changing standard conf files
> (and eventually wpa_supplication too).

You didn't mention which version of Lua you are using. I don't know if
it would help you, but there is the "inilazy" library by Alexandr
Leykin available at <>, for
"quick, lazy implementation for quick read ini-files into lua-tables."
It says it's for Lua 5.

I have a version with later enhancements [1] by Daniel Hertrich that's
been customized for NoteCase Pro, which is currently embedding Lua
5.3. It would need substituting some calls to the NoteCase Pro API
with other calls.

Looking at the code, it seems to want line endings rather than
space-delimited key value pairs. But that shouldn't be hard to work

Please let me know if you'd like a copy and if so I'll post it somewhere.

Best regards,


[1] Daniel's enhancements to the inilazy 1.04 beta are:

- added functions get_inikeyvalue() and set_inikeyvalue() for easy
access to the key/value pairs in the configuration table read from the
INI file by ini_get()

- In case of ini file not available, ini_get() now returns empty table
instead of nil, so that the Lua program can fill the table using the
above access functions

- The "true" assignment to key/value pairs in the configuration table,
introduced by Alexandr Leykin in inilazy v1.04beta, is now used to
distinguish valid key/value pairs from invalid ones (i.e. old /
obsolete ones, created by changing a value, which actually creates a
new key/value pair in the table with the same key and the new value,
and the old pair is invalidated by assigning "false")
This "valid" flag is checked when getting a value from the table and
when writing the table to disk. Only valid values are returned /
written. Invalid ones are abandoned.
This removes the inilazy feature of multiple lines with the same key
in one INI file section! Only one occurrence of the same key is
allowed now in one ini file section.

- ini_set(): writes only valid (="true") values to the file. Now only
one value per section / key is allowed.

- corrected example comment below ("into table: ...") (original
comment reflected code of version 1.03, not of version 1.04beta)

- Underscores in section names are now allowed

[Notice not included in the above original message:  The U.S. National
Security Agency neither confirms nor denies that it intercepted this