From 52f3a086f2ad7a3bbc9b8f8225a99e9e99120613 Mon Sep 17 00:00:00 2001 From: garret Date: Sat, 9 Oct 2021 15:19:59 +0100 Subject: finally add config stuff --- modules/garret/simpleconf.lua | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 modules/garret/simpleconf.lua (limited to 'modules/garret/simpleconf.lua') diff --git a/modules/garret/simpleconf.lua b/modules/garret/simpleconf.lua new file mode 100644 index 0000000..6d5f1a8 --- /dev/null +++ b/modules/garret/simpleconf.lua @@ -0,0 +1,46 @@ +-- primitive config handler + +local function tobool(value) + if value == "true" then + return true + elseif value == "false" then + return false + else + return nil + end +end + +local function cast(value) + return tonumber(value) or tobool(value) or value +end + +local function get_config(config_file, defaults) + local conf = defaults or {} + local ok, lines = pcall(io.lines, config_file) + if ok then + for line in lines do + local key, value = string.match(line, "(%a+)%s*=%s*(.+)") + conf[key] = cast(value) + end + end + return conf +end + +local simpleconf = {get_config = get_config} + + +local have_depctrl, depctrl = pcall(require, "l0.DependencyControl") + +if have_depctrl then + local version = depctrl{ + name = "Simple (bad) Config", + version = "0.1.0", + description = "primitive config handler", + author = "garret", + url = "http://github.com/garret1317/aegisub-scripts", + moduleName = "garret.simpleconf"} + simpleconf.version = version + return version:register(simpleconf) +else + return simpleconf +end -- cgit v1.2.3-70-g09d2