lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

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


a = { ['x'] = 1, ['y'] = 2}
b = { ['w'] = 4, ['z'] = 2}

return unpack(a) == unpack(b)

I hope this was useful and not too obvious for anyone.
Though, surely, it was discussed 100 times somewhere else.


Mario García H.