[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: nested entries in a configuration file
- From: Drake Wilson <drake@...>
- Date: Thu, 24 Feb 2011 11:23:37 -0700
Quoth "Henderson, Michael D" <michael.d.henderson@lmco.com>, on 2011-02-24 11:01:34 -0700:
> The configuration file looks like:
>
> database {
> entry { id = 'batch@raw'
> ,dev = account { host = 'rawdev' , name = 'batch01', instance = 'raw' }
> ,test = account { host = 'rawtest', name = 'batch11', instance = 'raw' }
> ,prod = account { host = 'rawprod', name = 'batch21', instance = 'raw' }
> },
> entry { id = 'batch@staging'
> ,dev = account { host = 'stgdev' , name = 'batch02', instance = 'staging' }
> ,test = account { host = 'stgtest', name = 'batch12', instance = 'staging' }
> ,prod = account { host = 'stgprod', name = 'batch22', instance = 'staging' }
> },
> }
Note that trailing commas are allowed in Lua table constructors, so
the initial-comma idiom is unnecessary unless there's some reason for
it I haven't seen before.
Also, curried function calls can be nice for this sort of thing:
foo 'bar' { baz = 'quux' }
is equivalent to:
foo('bar')({ baz = 'quux' })
and then you can handle the arguments in functional style:
function foo(bar)
return function(t)
return do_something_with(bar, t.baz, 'quuuux')
end
end
I wouldn't necessarily do that here; I'd just make the entry IDs into
keys. But if you don't want to generate the top-level table in one
go, you can also have functions that add entries to existing tables,
say, then postprocess things.
I don't know whether there's some other element that you think is ugly
or hard to understand compared to the other example, but those seem to
be the main differences.
---> Drake Wilson