I see it like this
t = {} t1 = {} setmetatable(t, t1) assert(getmetatable(t) == t1)
I read the wiki and I cant understand what its trying to say
Let the topic on OOP and metatables down for a second as they don't need to be used to explain assert (xy problem here?).
assert()
is a Lua function that simply checks if the first argument's value is not false or nil. If it is either then it will throw an error. If provided the second argument, of type string, it will use this as it's error message.
print(assert(1==2, "1 is not 2, silly.")) -- should fail --console: --> 12:24:38.803 - :2: 1 is not 2, silly.
The uses for this includes error debugging. It's not a requirement for oop practices.
In your case that's provided, it uses getmetatable()
to compare it to t1. Since t1 is the metatable for t then the assert should pass.
local t = {} local mt = {} setmetatable(t, mt) print(assert(getmetatable(t) == mt)) --true --If not then the error would give: assertion failed!