Boolean values represent the logical values of
true and false. Some languages represent these values as the integers 1 and 0,
respectively, while others represent them with the words True
and False
. In Lua, these values
are represented by (the lowercase) true
and false
.
Truthiness & Falsiness
In addition to the strictly boolean values, Lua also supports coercing non-boolean values into their boolean equivalents so that they can be used in boolean contexts.
This is such a common occurrence that it often makes sense to refer to non-boolean values as their
boolean-equivalents; values that are coerced to true
are considered truthy, while those that
are coerced to false
are regarded as falsy.
Value coercion in Lua is simple: Lua regards nil
to be falsy, and all other values are truthy.
This can lead to some surprising results result for those that are familiar with coercion in other
languages, where 0
, empty strings ""
, and empty collections {}
are usually regarded as being
falsy.