summaryrefslogtreecommitdiffstats
path: root/acf/util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acf/util.lua')
-rw-r--r--acf/util.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/acf/util.lua b/acf/util.lua
new file mode 100644
index 0000000..cbea072
--- /dev/null
+++ b/acf/util.lua
@@ -0,0 +1,37 @@
+--[[
+Copyright (c) 2012 Kaarle Ritvanen
+See LICENSE file for license details
+--]]
+
+module(..., package.seeall)
+
+function setdefaults(dst, src)
+ for k, v in pairs(src) do if dst[k] == nil then dst[k] = v end end
+ return dst
+end
+
+function copy(var)
+ return type(var) == 'table' and setdefaults({}, var) or var
+end
+
+function map(func, tbl)
+ local res = {}
+ for k, v in pairs(tbl) do res[k] = func(copy(v)) end
+ return res
+end
+
+
+local pth = require('acf.path')
+require 'lfs'
+
+function loadmods(subdir)
+ local comps = pth.split('/acf/'..subdir)
+ local res = {}
+ for modfile in lfs.dir(pth.join(unpack(comps))) do
+ if stringy.endswith(modfile, '.lua') then
+ local name = string.sub(modfile, 1, -5)
+ res[name] = require(table.concat(comps, '.')..'.'..name)
+ end
+ end
+ return res
+end