blob: cfecc91a938d900648c48181ff57ed2c8894f556 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
-- examples/configuration-lists.lua
--
-- Demonstrate lists in clod configurations
--
-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
--
clod = require "clod"
-- Clod's list support is a side-effect of its dictionary-like syntax
-- Essentially lists are not supported. In practice, Clod simulates
-- them by the ability to iterate subsets of the configuration.
-- You cannot usefully reorder lists, they're just dictionaries with
-- automatic keys. When Clod saves configurations, it changes trailing
-- i_[0-9]+ keys into a ["*"]. This is a tad 'magical' but never mind.
local configuration = [[
group.members["*"] "dsilvers"
group.members["*"] "liw"
wont.see.this "ERROR"
group.members["*"] "rjek"
group.members["*"] "robtaylor"
]]
conf, err = clod.parse(configuration)
if not conf then
error(err)
end
print("Input config:")
io.stdout:write(configuration)
print()
print()
print("Group members in the conf (by conf:each('group.members') iterator):")
for key, value in conf:each("group.members") do
print(key, value)
end
print()
print()
print("Serialised output:")
io.stdout:write(conf:serialise())
|