lua-users home
lua-l archive

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

2016-09-28 6:41 GMT+01:00 Russell Haley <>:
> 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:

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[1] end
config.check("myapp", {
    {type('number', "invalid foo"},
}, [[
usage: myapp [options] <foo>
    -foo <n>     a number
    -bar <bar>  a name

I don't usually serialize config, but I have a serializer module

With it I would save the config like that:

local dump = require 'dump'
local file ="myapp.conf", "wb")
for k,v in pairs(options) do
    file:write(k.." = "..dump.tostring(v).."\n")

Feel free to steal ideas, pieces of code or the whole thing. And I'd
be happy to answer any question about it :D