From 11243f851382e3618f05b6c4dd8a937c0c820ee0 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Thu, 23 Aug 2012 11:12:03 +0100 Subject: Initial examples, not all work --- examples/change-setting.lua | 24 ++++++++++++++++++++++++ examples/config-passthru.lua | 21 +++++++++++++++++++++ examples/simple-config-reader.lua | 18 ++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 examples/change-setting.lua create mode 100644 examples/config-passthru.lua create mode 100644 examples/simple-config-reader.lua diff --git a/examples/change-setting.lua b/examples/change-setting.lua new file mode 100644 index 0000000..bff5889 --- /dev/null +++ b/examples/change-setting.lua @@ -0,0 +1,24 @@ +-- examples/change-setting.lua +-- +-- Demonstration of changing a setting in Clod +-- +-- Copyright 2012 Daniel Silverstone +-- + +clod = require "clod" + +local input_config = [[ +project.name "jeff" +project.head "refs/heads/jeff" + +other.thing "here" +]] + +conf = clod.parse(input_config) + +conf.settings.project.name = "Clod" +conf.settings.project.head = "refs/heads/jeff" +conf.settings.project.description = "Demonstration of settings" + +print(conf:serialise()) + diff --git a/examples/config-passthru.lua b/examples/config-passthru.lua new file mode 100644 index 0000000..83c2769 --- /dev/null +++ b/examples/config-passthru.lua @@ -0,0 +1,21 @@ +-- examples/config-passthru.lua +-- +-- Demonstration of re-serialising a configuration in Clod +-- +-- Copyright 2012 Daniel Silverstone +-- + +clod = require "clod" + +local input_config = [[ +something "here" + +other.thing "there" +]] + +conf, err = clod.parse(input_config) +if not conf then + error(err) +end + +io.stdout:write(conf:serialise()) diff --git a/examples/simple-config-reader.lua b/examples/simple-config-reader.lua new file mode 100644 index 0000000..b1b4719 --- /dev/null +++ b/examples/simple-config-reader.lua @@ -0,0 +1,18 @@ +-- examples/simple-config-reader.lua +-- +-- Simple configuration reader which interrogates only specific keys +-- +-- Copyright 2012 Daniel Silverstone +-- + +clod = require "clod" + +local configuration = [[ +project.name "Clod" +project.head "refs/heads/master" +]] + +conf = clod.parse(configuration) + +print("Project name is", conf.settings["project.name"]) +print("Project HEAD is", conf.settings.project.head) -- cgit v1.2.1