From 94f7fc0d3e410a7c7dc6f6cffe0ed87238608391 Mon Sep 17 00:00:00 2001 From: the lemons Date: Mon, 19 Dec 2022 18:28:46 -0600 Subject: world made of chunks with objects in them --- util.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 util.lua (limited to 'util.lua') diff --git a/util.lua b/util.lua new file mode 100644 index 0000000..a639ca2 --- /dev/null +++ b/util.lua @@ -0,0 +1,30 @@ + +local M = {} + +function M.copy(t) + local c = {} + for k,v in pairs(t) do + c[k] = v + end + return c +end + +function M.deepcopy(t) + local copied = {} + local function dc(t) + if not copied[t] then + local c = {} + copied[t] = c + for k,v in pairs(t) do + if type(v) == 'table' then + v = dc(v) + end + c[k] = v + end + end + return copied[t] + end + return dc(t) +end + +return M -- cgit v1.2.3