summaryrefslogtreecommitdiff
path: root/lib/gall/util.lua
blob: 48181be6f1108ab2667f4c2d2d9bc4169947f2f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- gall.ll
--
-- Git Abstraction Layer for Lua -- Utility functions
--
-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
--
--

local function deep_copy(t, memo)
   if not memo then memo = {} end
   if memo[t] then return memo[t] end
   local ret = {}
   memo[t] = ret
   local kk, vv
   for k, v in pairs(t) do
      kk, vv = k, v
      if type(k) == "table" then
	 kk = deep_copy(k, memo)
      end
      if type(v) == "table" then
	 vv = deep_copy(v, memo)
      end
      ret[kk] = vv
   end
   return ret
end

return {
   deep_copy = deep_copy,
}