From a278292101608a2fc1c2ebb3a46f883b2ffc7076 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 25 Aug 2012 10:36:28 +0100 Subject: CLOD: Add rudimentary list support so we can convert Gitano's group configs --- examples/configuration-lists.lua | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/configuration-lists.lua (limited to 'examples/configuration-lists.lua') 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 +-- + +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 -- cgit v1.2.1