logical operators
The logical operators are and, or, and not. Like control structures, all logical operators consider false and nil as false and anything else (including zero) as true. The operator and returns its first argument if it is false; otherwise, it returns its second argument. The operator or returns its first argument if it is not false, otherwise, it returns its second argument.
Both and and or use short-cut evaluation, that is, they evaluate their second operand only when necessary.
A useful technique is to use the ability of or to return its first argument if it is not false to quickly test if a variable exists. For example:
Both and and or use short-cut evaluation, that is, they evaluate their second operand only when necessary.
A useful technique is to use the ability of or to return its first argument if it is not false to quickly test if a variable exists. For example:
t = t or {} -- create table if it does not exist
The operator not always returns true or false.Lua keyword/topics
- assignment
- break
- comments
- data types
- do
- for (generic)
- for (numeric)
- function
- identifiers
- if / then / else
- keywords
- local
- precedence
- relational operators
- repeat
- return
- string literals
- tables
- while
Topics
- Lua LPEG library
- Lua PCRE regular expression functions
- Lua SQLite (database) interface
- Lua base functions
- Lua bc (big number) functions
- Lua bit manipulation functions
- Lua coroutine functions
- Lua debug functions
- Lua io functions
- Lua math functions
- Lua os functions
- Lua package functions
- Lua script extensions
- Lua string functions
- Lua syntax
- Lua table functions
- Lua utilities
- Scripting callbacks - plugins
- Scripting