From 31aac07de77fa38cd8eb3065aa7b57034b951e02 Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 20 Nov 2022 11:38:27 +0000 Subject: feedmaker: add key:value table merger --- make-feed.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'make-feed.lua') 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 -- cgit v1.2.3-70-g09d2