summaryrefslogtreecommitdiff
path: root/util.lua
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-12-19 18:28:46 -0600
committerthe lemons <citrons@mondecitronne.com>2022-12-19 18:28:46 -0600
commit94f7fc0d3e410a7c7dc6f6cffe0ed87238608391 (patch)
tree805c7a90ed1adf9bf358868f19ef1e9a072b791d /util.lua
parentba1b317b3b4de92d7f39dceb988a41840e4fc942 (diff)
world made of chunks with objects in them
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua30
1 files changed, 30 insertions, 0 deletions
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