Objective
LUA has 6 data types, nil (empty), Boolean (Boolean), number (numeric), string (character), table (table), function (functions)
You can use the type function in Lua to return a value or the type to which a variable belongs, such as:
Print (Type ("Helle World"))-->output:stringprint (type (print))-->output:functionprint (type (TRUE))-- Output:boolean
1. Nil (empty)
Lua uses nil to denote an "invalid value." The default value is nil before the first assignment of a variable, and the nil assignment to a global variable is equivalent to deleting it.
Local numprint (num)-->output:nilnum = 100print (num)-->output:100
num = nil print (num)-->output:nil
2. Boolean (Boolean)
The optional Boolean value is True/false, nil and false in Lua are false, and the rest is true, such as 0 and null characters are true.
3. Number (numeric)
Number is used to represent real numbers, you can use the Math function Math.floor (rounding down), Math.ceil (rounding up)
Localorder=3.0localscore=98.5print (Math.floor (order))-->output:3print (Math.ceil (score))-->output:99
4. String (character)
In Lua, there are three ways to represent strings:
1) Use a pair of single quotes. such as: ' Hello '
2) Use a pair of double quotation marks. such as: "Hello"
3) Use braces (that is, [[]]) to define.
Note: The transfer character in Lua's string does not work.
The LUA string is a non-modifiable value and cannot be modified as a character of a string directly in the C language, but instead creates a new string based on the modification requirement.
LUA also cannot access a character of a string by subscript.
LOCALSTR3 = [["Add\name", ' hello ']]LOCALSTR4 = [=[stringhavea[[]]. =]print (STR1)-->output:helloworldprint (str2)-->output:helloluaprint (STR3)-->output: "Add\name", ' Hello ' Print (STR4)-->output:string has a [[]].
5. Table (Tables)
The table type implements an abstract "associative array". An associative array is an array that has a special index, which is usually a string or number type, but can also be a value of any type except nil.
6. function (Functions)
In Lua, a function is also a data type that can be stored in a variable, passed to other functions by argument, and can be used as a return value for other functions.
The function ends with end.
Local function foo () print ("In the Function")--dosomething () Local x = ten local y = return x + yendlocal a = foo- -Assign the function to the variable print (A ())--output:in the Function30
Lua learns----LUA basic data types