Log In  

Cart #bugtest-0 | 2024-01-13 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

function _init()
    last={{0,0},{0,0}}
    def={{0,0},{0,0}}
    --shouldn't throw error
    assert(last==def)
end

These metatables are identical, but for some reason, they are not considered equal. Why is this? I tested something similar with regular tables and they work just fine, so I doubt metatable comparisons aren't supported by PICO-8. Does anyone know what's happening here?

P#140083 2024-01-13 19:58

Terminology: Those are just regular tables. Metatables are special tables that control how a table functions.

As for why they are considered different, Lua does not do a deep compare on tables. The == operator will only tell you if the table referred to by a variable is the same one referred to by another. For instance:

> t1 = { 1, 2, 3 }
> t2 = { 1, 2, 3 }
> t3 = t2  -- this copies the reference, not the table
> print( t1 == t2 )
false
> print( t2 == t3 )
true
P#140085 2024-01-13 20:04
1

Thanks for the help!

P#140086 2024-01-13 20:55

[Please log in to post a comment]