diff options
author | garret <garret@airmail.cc> | 2022-11-20 11:38:27 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2022-11-20 11:39:15 +0000 |
commit | 31aac07de77fa38cd8eb3065aa7b57034b951e02 (patch) | |
tree | c5f3a36a4e4c07a7e3f915c62171b252de4eea16 /make-feed.lua | |
parent | f45a1d1900a4e200955018859d55834a37aded3b (diff) | |
download | depctrl-feedmaker-31aac07de77fa38cd8eb3065aa7b57034b951e02.tar.gz depctrl-feedmaker-31aac07de77fa38cd8eb3065aa7b57034b951e02.tar.bz2 depctrl-feedmaker-31aac07de77fa38cd8eb3065aa7b57034b951e02.zip |
feedmaker: add key:value table merger
Diffstat (limited to 'make-feed.lua')
-rwxr-xr-x | make-feed.lua | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/make-feed.lua b/make-feed.lua index d8626e5..a28e372 100755 --- a/make-feed.lua +++ b/make-feed.lua @@ -37,13 +37,24 @@ local function clean_path(path, file) return path .. "/" .. file end -local function join_tables(dst, src) +local function join_itables(dst, src) + if dst == nil then return src end + if src == nil then return dst end for i, v in ipairs(src) do table.insert(dst, v) end return dst end +local function join_ktables(dst, src) + if dst == nil then return src end + if src == nil then return dst end + for k, v in pairs(src) do + dst[k] = v + end + return dst +end + local function readfile(filename) local f = io.open(filename) local txt = f:read("*all") @@ -72,7 +83,7 @@ local function get_files(path) local name, extension = file:match("^(.*)%.(.*)$") -- anything.anything local absolute = clean_path(path, file) if file == "." or file == ".." then -- silently skip dir and 1-level-up dir - elseif pcall(lfs.dir, absolute) then file = join_tables(files, get_files(absolute)) -- search recursively + elseif pcall(lfs.dir, absolute) then file = join_itables(files, get_files(absolute)) -- search recursively elseif extension ~= "lua" then err(absolute .. ": not a lua file, skipping") elseif not valid_namespace(name) then err(absolute .. ": invalid namespace, skipping") else table.insert(files, absolute) end |