undo.lua 482 B

1234567891011121314151617
  1. -- https://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value/26367080#26367080
  2. function deepcopy(obj, seen)
  3. if type(obj) ~= 'table' then return obj end
  4. if seen and seen[obj] then return seen[obj] end
  5. local s = seen or {}
  6. local result = setmetatable({}, getmetatable(obj))
  7. s[obj] = result
  8. for k,v in pairs(obj) do
  9. result[deepcopy(k, s)] = deepcopy(v, s)
  10. end
  11. return result
  12. end
  13. function minmax(a, b)
  14. return math.min(a,b), math.max(a,b)
  15. end