From 89e494b46fbe120e012f4a13cfffc5f85cd9ad89 Mon Sep 17 00:00:00 2001 From: garret Date: Thu, 1 Dec 2022 00:06:20 +0000 Subject: add deepcopy from lua-users --- make-feed.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'make-feed.lua') 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) -- cgit v1.2.3-70-g09d2