Logical operators

The logical operators in Lua are and, or, and not. Like the control structures (see Control Structures), all logical operators consider both false and null as false and anything else as true.

The negation operator not always returns false or true. The conjunction operator and returns its first argument if this value is false or null; otherwise, and returns its second argument. The disjunction operator or returns its first argument if this value is different from null and false; otherwise, or returns its second argument. Both and and or use short-cut evaluation; that is, the second operand is evaluated only if necessary. Here are some examples:
±------------------±--------------±--------------±-----------±-----------+
| 10 | > or | > 20 | | > --> 10 |
±------------------±--------------±--------------±-----------±-----------+
| 10 | > or | > error() | > --> 10 | |
±------------------±--------------±--------------±-----------±-----------+
| null or “a” | > --> “a” | | | |
±------------------±--------------±--------------±-----------±-----------+
| null and | 10 | > --> null | | |
±------------------±--------------±--------------±-----------±-----------+
| false and error() | > --> false | | | |
±------------------±--------------±--------------±-----------±-----------+
| false and | null | > --> false | | |
±------------------±--------------±--------------±-----------±-----------+
| false or | | > --> null | | |
±------------------±--------------±--------------±-----------±-----------+
| 10 | > and 20 | | > --> 20 | |
±------------------±--------------±--------------±-----------±-----------+

--> indicates the result of the preceding expression.