function table.len(t)
local len=0
table.foreach(t,
function (k,v)
len=len+1
end
)
return len;
end
print(table.len({1,2,nil,4}))
print(table.len({nil,1,2,nil,3,nil,4}))
print(table.len({nil,'a',2,nil,3,nil,4,nil,'b'}))
print(table.len({2,3,4,5,6}))
t={}
t.a=nil
t.b=1
t.c=2
t.d=nil
t.e=3
t[3]='a'
print(table.len(t))
function table.compare(t1,t2)
if table.len(t1)~=table.len(t2) then return false; end
table.foreach(t1,
function(k,v)
if v~=t2[k] and type(v)~='table' then
return false;
elseif v~=t2[k] then
return table.compare(v,t2[k])
end
end
)
return true;
end
tt={a=1,nil,2,{}}
tt1={1,2,t,3,b=3,d=nil}
tt2={1,nil,b=3,2,nil,c=nil,3,t}
print(table.compare(tt1,tt2))