Lua Programming/How to Lua/variable
A variable is a symbolic name associated with a value. A variable acts as a container and the value it contains may be changed from within a running program, enabling data manipulation to take place from within the program.
- 1 Variables are dynamically typed.
- 2 Variables do not need predefinition prior to use
- 3 Variable names
- 4 Variables do not need a sigil
- 5 Variables are global by default
- 6 Variable names inside string constants are not expanded in Lua
- 7 Local variables have lexical scope
- 8 Global variables are stored in environment tables
Variables are dynamically typed.
In lua variables are dynamically typed, so no explicit typecasting is necessary.
Variables do not need predefinition prior to use
As in most programming languages, the name of a variable must be a sequence of letters, digits, or underscore symbols, and may not begin with a digit. The Lua interpreter is lettercase sensitive so variables with uppercase and lowercase names are distinct and separate from each other. It is not permissible to use keywords as variable names.
Variables do not need a sigil
Variables are global by default
Variable names inside string constants are not expanded in Lua
The lua interpreter does not expand variables inside string constants. This means that "hello username" is always interpreted as constant string, even if username is a the name of a variable. Instead of using interpolation, new strings are constructed from string constants and variables, using concatenation operators.