about summary refs log tree commit diff stats
path: root/undo.lua
diff options
context:
space:
mode:
Diffstat (limited to 'undo.lua')
-rw-r--r--undo.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/undo.lua b/undo.lua
new file mode 100644
index 0000000..fcfdb6a
--- /dev/null
+++ b/undo.lua
@@ -0,0 +1,16 @@
+-- https://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value/26367080#26367080
+function deepcopy(obj, seen)
+  if type(obj) ~= 'table' then return obj end
+  if seen and seen[obj] then return seen[obj] end
+  local s = seen or {}
+  local result = setmetatable({}, getmetatable(obj))
+  s[obj] = result
+  for k,v in pairs(obj) do
+    result[deepcopy(k, s)] = deepcopy(v, s)
+  end
+  return result
+end
+
+function minmax(a, b)
+  return math.min(a,b), math.max(a,b)
+end