-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcopy.lua
More file actions
32 lines (29 loc) · 718 Bytes
/
copy.lua
File metadata and controls
32 lines (29 loc) · 718 Bytes
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
31
32
local RingMenu_AddonName, RingMenu = ...
-- Shallow-copy a table
function RingMenu.shallow_copy(t)
local copy = {}
for k, v in pairs(t) do
copy[k] = v
end
return copy
end
-- Deep-copy a table
function RingMenu.deep_copy(t)
local copy = {}
if type(t) == 'table' then
for k, v in pairs(t) do
copy[RingMenu.deep_copy(k)] = RingMenu.deep_copy(v)
end
else
copy = t
end
return copy
end
-- Copies fields from defaults to t but only if they are currently nil in t
function RingMenu.update_with_defaults(t, defaults)
for k, v in pairs(defaults) do
if t[k] == nil then
t[k] = RingMenu.deep_copy(v)
end
end
end