assignment
Assignment lets you "assign" (set) a variable to a value.
eg.
Multiple assignments are not generally used on their own (they can be confusing to read), except in collecting the results from a function. Functions can return multiple results, so multiple assignment is a useful way of getting those results. eg.
With multiple assignment, if you (or the function) provides too few values, the extra ones are set to nil, eg.
If you provide too many values, the extra ones are silently discarded, eg.
eg.
a = 42
b = "hello"
You can do multiple assignments, eg.
a, b = 42, "hello"
That does the same thing as the first example.Multiple assignments are not generally used on their own (they can be confusing to read), except in collecting the results from a function. Functions can return multiple results, so multiple assignment is a useful way of getting those results. eg.
a, b, c = string.find ("the quick brown fox", "(a+)")
In this example, a will get the start character position of the match, b will get the end position, and c will get the capture.
With multiple assignment, if you (or the function) provides too few values, the extra ones are set to nil, eg.
a, b, c, d = 0, 1
This sets a to 0, b to 1, and c and d are both set to nil.
If you provide too many values, the extra ones are silently discarded, eg.
a = 1, 2, 3, 4, 5, 6
The values 2, 3, 4, 5, 6 are just discarded.Lua keyword/topics
- break
- comments
- data types
- do
- for (generic)
- for (numeric)
- function
- identifiers
- if / then / else
- keywords
- local
- logical operators
- 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