TABLE.copy新增depth参数

This commit is contained in:
MrZ626
2021-08-08 18:18:11 +08:00
parent 7682054dea
commit e50fe63e02

View File

@@ -24,14 +24,15 @@ function TABLE.shift(org)
return L
end
--Get a full copy of a table
function TABLE.copy(org)
--Get a full copy of a table, depth = how many layers will be recreate, default to inf
function TABLE.copy(org,depth)
if not depth then depth=1e99 end
local L={}
for k,v in next,org do
if type(v)~='table'then
if type(v)~='table'or depth==0 then
L[k]=v
else
L[k]=TABLE.copy(v)
L[k]=TABLE.copy(v,depth-1)
end
end
return L