diff options
author | garret <garret@airmail.cc> | 2022-12-01 00:06:20 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2023-02-16 05:29:21 +0000 |
commit | 89e494b46fbe120e012f4a13cfffc5f85cd9ad89 (patch) | |
tree | 3c967b9a47331b05247ae089cf984c55956293c9 /make-feed.lua | |
parent | ad768134264b827ff20f1453e11c1074479ea352 (diff) | |
download | depctrl-feedmaker-89e494b46fbe120e012f4a13cfffc5f85cd9ad89.tar.gz depctrl-feedmaker-89e494b46fbe120e012f4a13cfffc5f85cd9ad89.tar.bz2 depctrl-feedmaker-89e494b46fbe120e012f4a13cfffc5f85cd9ad89.zip |
add deepcopy from lua-users
Diffstat (limited to 'make-feed.lua')
-rwxr-xr-x | make-feed.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/make-feed.lua b/make-feed.lua index e4995fa..a0bcc89 100755 --- a/make-feed.lua +++ b/make-feed.lua @@ -105,6 +105,27 @@ local function get_file_metadata(file) return hash, lastmodified end +local function deepcopy(orig, copies) -- copied and pasted from https://lua-users.org/wiki/CopyTable + copies = copies or {} + local orig_type = type(orig) + local copy + if orig_type == 'table' then + if copies[orig] then + copy = copies[orig] + else + copy = {} + copies[orig] = copy + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key, copies)] = deepcopy(orig_value, copies) + end + setmetatable(copy, deepcopy(getmetatable(orig), copies)) + end + else -- number, string, boolean, etc + copy = orig + end + return copy +end + local noop = function() end local function fake_depctrl(i) |