Introduction to Lua Types
Lua is a dynamically typed language, which means that variables do not have types; only values do. There are no type definitions in the language. All values carry their own type.
In Lua, there are eight basic types:
- nil: represents the absence of a useful value
- boolean: has two values - false and true
- number: represents real (double-precision floating-point) numbers
- string: represents arrays of characters
- function: represents a first-class value with code
- userdata: represents arbitrary C data
- thread: represents independent threads of execution
- table: represents ordinary arrays, symbol tables, sets, records, graphs, trees, etc.
The function type
returns a string describing the type of a given value:
print(type("Hello world")) --> string
print(type(10.4)) --> number
print(type(true)) --> boolean
print(type(nil)) --> nil
print(type(type(10.4))) --> string