15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
105
106
107
108
109
110
111
112
113
|
fn.copy = function(t)
local new = {}
for i,v in pairs(t) do new[i] = v end
setmetatable(new,getmetatable(t))
return new
end
fn.merge = function(base,override)
local new = fn.copy(base)
for k,v in pairs(override) do
new[k] = v
end
return new
end
fn.append = function(r1, r2)
local new = fn.copy(r1)
for i=1,#r2 do
................................................................................
else
for i=0,#tbl do
acc = fn(acc,tbl[i],i)
end
end
return acc
end
return fn
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
fn.copy = function(t)
local new = {}
for i,v in pairs(t) do new[i] = v end
setmetatable(new,getmetatable(t))
return new
end
fn.deepcopy = table.copy or function(t)
new = {}
for k,v in pairs(t) do
if type(v) == 'table' then
new[k] = fn.deepcopy(v)
else
new[k] = v
end
end
return new
end
fn.merge = function(base,override)
local new = fn.copy(base)
for k,v in pairs(override) do
new[k] = v
end
return new
end
fn.deepmerge = function(base,override)
local new = {}
local keys = fn.merge(fn.keys(base),fn.keys(override))
for _,k in pairs(keys) do
if type(base[k]) == 'table' and
type(override[k]) == 'table' then
new[k] = fn.deepmerge(base[k], override[k])
elseif override[k] then
new[k] = override[k]
else
new[k] = base[k]
end
end
return new
end
fn.append = function(r1, r2)
local new = fn.copy(r1)
for i=1,#r2 do
................................................................................
else
for i=0,#tbl do
acc = fn(acc,tbl[i],i)
end
end
return acc
end
fn.walk = function(tbl,path)
if type(path) == 'table' then
for _,p in pairs(path) do
if tbl[p] == nil then return nil end
tbl = tbl[p]
end
else
tbl = tbl[path]
end
return tbl
end
return fn
|