Lua is a dynamic type language, so a variable has no type, and only the value has a type. Values can be stored in a variable, passed as a parameter, and returned as a result.
Although we do not have variable data types in Lua, we have types of values. The list used for numeric data types is given below.
function Type
In Lua there is a type called function that allows us to know the type of the variable. Here are some examples of the following code.
Copy Code code as follows:
Print (Type ("What is my Type")--> string
t=10
Print (Type (5.8*t))--> number
Print (Type (true))--> Boolean
Print (type (print))--> function
Print (type)--> function
Print (type (nil))--> Nil
Print (Type (ABC))--> string
When the above program is established and executed, it will produce results under Linux:
Copy Code code as follows:
String
Number
function
function
Boolean
Nil
String
By default, all variables will point to nil until they are assigned a value or initialized. In Lua, 0 and empty strings are considered true, as are conditional checks. Therefore, you must be careful when using Boolean operations. We'll learn more and use these types in the following sections.