TABLE.copy新增depth参数
This commit is contained in:
@@ -24,14 +24,15 @@ function TABLE.shift(org)
|
|||||||
return L
|
return L
|
||||||
end
|
end
|
||||||
|
|
||||||
--Get a full copy of a table
|
--Get a full copy of a table, depth = how many layers will be recreate, default to inf
|
||||||
function TABLE.copy(org)
|
function TABLE.copy(org,depth)
|
||||||
|
if not depth then depth=1e99 end
|
||||||
local L={}
|
local L={}
|
||||||
for k,v in next,org do
|
for k,v in next,org do
|
||||||
if type(v)~='table'then
|
if type(v)~='table'or depth==0 then
|
||||||
L[k]=v
|
L[k]=v
|
||||||
else
|
else
|
||||||
L[k]=TABLE.copy(v)
|
L[k]=TABLE.copy(v,depth-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return L
|
return L
|
||||||
|
|||||||
Reference in New Issue
Block a user