Answered by
6 years ago Edited 6 years ago
~=
is Lua's inequality comparison operator.
a ~= b
will evaluate to true
if a
and b
are not equal. However if either a
or b
have a metatable with an __eq
field set to a function then Lua will call that function instead. To avoid calling this function and perform a raw comparison, Lua provides a function call rawequal
which compares a
and b
without invoking the __eq
metamethod.
This last bit of information is really only of use to you if you make use of metatables, but I found it interesting to bring up anyway.
An interesting thing to note about equality comparisons is that {} == {}
will never be true
, as tables are compared by reference and not by value. This means that a variable holding a table will only ever be equal to another if the second refers to the same table in memory:
Yet another thing to note is that NaN
-- a special number constant meaning "Not a Number" and returned by undefined math operations -- equals nothing, not even itself.