Posted 06 December 2014 - 05:17 AM
Hey guys. So, I need something explained. First of all, what exactly is the first parameter in __index and __newindex metamethods? Secondly, can you compare tables? (just making sure…)
print( {} == {} ) --#prints false
local compareTables
function compareTables( tA, tB )
for k, v in pairs( tA ) do
if type( v ) ~= "table" and v ~= tB[ k ] then
return false
elseif type( v ) == "table" and ( type( tB[ k ] ) ~= "table" or not compareTables( v, tB[k] ) ) then
return false
end
end
return true
end
First off: __index doesn't take a parameter. I believe you want this.
Second: Sort of…print( {} == {} ) --#prints false local compareTables function compareTables( tA, tB ) for k, v in pairs( tA ) do if type( v ) ~= "table" and v ~= tB[ k ] then return false elseif type( v ) == "table" and ( type( tB[ k ] ) ~= "table" or not compareTables( v, tB[k] ) ) then return false end end return true end
local table = {}
print(compare(table, table)) -- true
-snip-
Oh, I am talking about __index as a function by the way…
local t = {}
print( t == t ) --#prints true