Lua: Booleans

From Mario Fan Games Galaxy Wiki
Revision as of 03:11, 27 September 2009 by Xgoff (talk | contribs) (Created page with '{{Lua}} Up until Lua 5.0, Lua did not have an explicit '''boolean''' type; instead, boolean operations were performed using <tt>nil</tt> as <tt>false</tt> and any other n…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Lua
Lua.gif
Basics
Intermediate
Advanced
XLua
Add to this template
 Standardwikimessagebox.png This article assumes the use of Lua 5.1.

Information may not be accurate or may need revision if you are using a different version.

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.