Lua: Booleans
From Mario Fan Games Galaxy Wiki
Lua |
---|
Basics |
Intermediate |
Advanced |
|
XLua |
Add to this template |
Up until Lua 5.0, Lua did not have an explicit boolean type; instead, boolean operations were performed using nil as false and any other non-nil datatype as true. Lua 5.0 introduced true and false as a true and separate boolean type. However, non-boolean values are still valid in boolean expressions, as they will be automatically coerced following the old behavior: nil as false, anything else as true.
Boolean coercion allows for some shortcuts in syntax; for example, an if statement may look like if test == true then; however, the explicit check for true is unnecessary: if test then is also legal, and shorter. not may also be used instead of testing for equality to false.