[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reading a conf file
- From: Sean Conner <sean@...>
- Date: Wed, 28 Sep 2016 02:25:00 -0400
It was thus said that the Great Russell Haley once stated:
> (Sorry about the empty message. Error Behind Keyboard...)
>
> On Tue, Sep 27, 2016 at 11:06 PM, Paul Merrell <marbux@gmail.com> wrote:
> > On Tue, Sep 27, 2016 at 10:41 PM, Russell Haley <russ.haley@gmail.com> 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 <http://luaforge.net/projects/inilazy/>, 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
> > around.
> >
> > Please let me know if you'd like a copy and if so I'll post it somewhere.
>
> Much appreciated Paul, I'm using 5.3, but I am only supporting FreeBSD
> and Debian GNU/Linux at this time so INI files are not a requirement.
> I found a copy of the original inilazy on the web that I will review
> for hints, but I think I'll go with the loadfile solution.
If you do need to support INI files, I also have a module to read them
into a Lua table using LPeg [1]. It can also be installed via LuaRocks:
luarocks install org.conman.parsers.ini
and to use it:
local ini = require "org.conman.parsers.ini"
local CONF do
local f = io.open("my-configfile.ini","r")
local d = f:read("*a")
f:close()
CONF = ini:match(d)
end
An example of the type of INI file and resulting Lua table can be found at
the bottom of
https://github.com/spc476/LPeg-Parsers/blob/master/README
-spc
[1] https://github.com/spc476/LPeg-Parsers/blob/master/ini.lua