Data types
There are different data types provided by the language:
number
All numeric values has number
type. Internally it holds double precision floating point value. There is not special type for integer numbers, all numbers are floating point.
boolean
A boolean type which can hold either true
or false
values. It's usually used for logic expressions and conditions checking.
string
String, well, is a string. A list of character.
function
This is a data type for storing all types of functions: usual Lua functions, anonymous Lua functions and C functions.
table
Lua table is a key-value map. Table is a general type for representing all sorts of complex entities: arrays, maps, objects, trees, etc.
thread
A type representing a thread. Lua threads aren't OS threads. Multitasking in Lua is implemented with coroutines and Lua thread is a coroutine context.
userdata
This type is used for underlying C user data.
nil
Unlike all other Lua types, nil
means only one thing: there is no value.
You can check a type of a value with a built-in Lua function called type
:
a = 15
b = "Hello"
c = 5 > 3
d = nil
print(type(a)) -- number
print(type(b)) -- string
print(type(c)) -- boolean
print(type(d)) -- nil
Since Lua has dynamic type system, you can reassign a variable with a value which has a different type:
foo = 15
print(type(foo)) -- number
foo = "Now I am a string!"
print(type(foo)) -- string