diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-25 10:36:28 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-25 10:36:28 +0100 |
commit | a278292101608a2fc1c2ebb3a46f883b2ffc7076 (patch) | |
tree | 859cb7c6d96bd3e1886fc6ec4472dfd42885c076 /examples | |
parent | 8797eb9b4b15729396ea049f8459e351d3093728 (diff) | |
download | clod-a278292101608a2fc1c2ebb3a46f883b2ffc7076.tar.gz |
CLOD: Add rudimentary list support so we can convert Gitano's group configs
Diffstat (limited to 'examples')
-rw-r--r-- | examples/configuration-lists.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/configuration-lists.lua b/examples/configuration-lists.lua new file mode 100644 index 0000000..cfecc91 --- /dev/null +++ b/examples/configuration-lists.lua @@ -0,0 +1,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())
\ No newline at end of file |