[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Table compare
- From: "G.H." <code933k@...>
- Date: Sat, 27 Dec 2008 13:17:34 -0500
By the way, "tables" is what you asked for [...]
> function compareTables(t1, t2)
> return (#a == #b) and (unpack(t1) == unpack(t2))
> end
This unpack usage is -obviously- just limited to _regular tables_.
"Dictionary" alike usage will not work unless you replace unpack()
with the first loop you posted:
> for k, v in pairs(t1) do
> if t2[k] ~= v then return false end
> end
Otherwise:
a = { ['x'] = 1, ['y'] = 2}
b = { ['w'] = 4, ['z'] = 2}
return unpack(a) == unpack(b)
true
I hope this was useful and not too obvious for anyone.
Though, surely, it was discussed 100 times somewhere else.
Cheers.
--
Mario García H.