The relational operators in Lua are
== ~= < > <= >=
These operators always result in false or true.
Equality (==
) first compares the type of its operands. If the types are different, then the result is false. Otherwise, the values of the operands are compared. Numbers and strings are compared in the usual way. Objects (tables, userdata, threads, and functions) are compared by reference: two objects are considered equal only if they are the same object. Every time you create a new object (a table, userdata, thread, or function), this new object is different from any previously existing object.
You can change the way that Lua compares tables and userdata by using the "eq" metamethod (see Metatables).
The conversion rules of Coercion do not apply to equality comparisons. Thus, "0"==0
evaluates to false, and t[0]
and t["0"]
denote different entries in a table.
The operator ~=
is exactly the negation of equality (==
).
The order operators work as follows. If both arguments are numbers, then they are compared as such. Otherwise, if both arguments are strings, then their values are compared according to the current locale. Otherwise, Lua tries to call the "lt" or the "le" metamethod (see Metatables).