[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reading a conf file
- From: Russell Haley <russ.haley@...>
- Date: Wed, 28 Sep 2016 10:22:08 -0700
Thanks Jerome, I'll check that out and appreciate the *for theft* clause!
Russ
On Wed, Sep 28, 2016 at 9:41 AM, Jerome Vuarand
<jerome.vuarand@gmail.com> wrote:
> 2016-09-28 6:41 GMT+01:00 Russell Haley <russ.haley@gmail.com>:
>> 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).
>
> What is "standard conf files"?
>
>> Any feedback would be dandy.
>
> Like others that already replied, I use the Lua parser for all my
> config files. I wrote a simple module that handles that:
> https://bitbucket.org/doub/config
>
> A typical usage example goes like this:
>
> local config = require 'config'
> local options = {
> foo = 42,
> bar = "hello",
> baz = nil,
> }
> config.load(options, "myapp.conf")
> config.args(options, ...)
> if #options >= 1 then options.foo = options[1] end
> config.check("myapp", {
> {type(options.foo)=='number', "invalid foo"},
> }, [[
> usage: myapp [options] <foo>
> options:
> -foo <n> a number
> -bar <bar> a name
> ]])
>
> I don't usually serialize config, but I have a serializer module
> there: https://bitbucket.org/doub/dump
>
> With it I would save the config like that:
>
> local dump = require 'dump'
> local file = io.open("myapp.conf", "wb")
> for k,v in pairs(options) do
> file:write(k.." = "..dump.tostring(v).."\n")
> end
> file:close()
>
> Feel free to steal ideas, pieces of code or the whole thing. And I'd
> be happy to answer any question about it :D
>