1 2 3 4 5 6 7

Data types


There are different data types provided by the language:


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.


A boolean type which can hold either true or false values. It's usually used for logic expressions and conditions checking.


String, well, is a string. A list of character.


This is a data type for storing all types of functions: usual Lua functions, anonymous Lua functions and C functions.


Lua table is a key-value map. Table is a general type for representing all sorts of complex entities: arrays, maps, objects, trees, etc.


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.


This type is used for underlying C user data.


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
Rate this post:
Lesson 3
Lesson 5
Share this page:

Learning plan

What is Lua script and what are these tutorials about
The most simple Lua program and where you can run it
A very brief overview of Lua syntax and expressions
4. Data types
A list of data types and their descriptions which Lua operates on
A list of built-in operators in Lua
A list of Lua statements which you use to organize control flow of a program
What kind of functions are there and how to write them