1. Strings are connected using the. Such as
Print (123.. 44)
Output 12344
Print (' a '.. ' B ')
Output AB
Print (123.. 44) The time of the sentence. Space on both sides
2. Lua annotation Symbols
Single line--
MultiRow
--[[
Here is the comment
--]]
3. String blocks
stringblock=[[
This is a string
Block
]]
4. Null type nil equals NULL, if a variable is unassigned, its value is nil, and the nil value in the conditional statement is false, for example
If Nil Then
Print (' nil ')
Else
Print (' nil is false ')
End
Output
Nil is False
5. # Put in front of string to calculate string length
STR1 = "This is a string"
Print (#str1)
Output
16
6. Table data type
This type is interesting, representing an associative array, a bit like a dictionary structure, where numbers and strings can be indexed
a={}--Empty table
a["key"]= ' value '
A[10]=22
For k,v in pairs (a) do
Print (k ... ":"). V
End
Output
: value:33
Here Pairs () is a function that can be viewed with print (type pairs), not specified in the usage ... I'll see you back.
In addition, the default index for table is starting from 1
tbl = { "Apple" , "pear" , "Orange" , "grape" }< Span class= "KWD" >for Key, val in Pairs (tbl do< Span class= "PLN" > print ( "Key" Key) end
Output
Key 1
Key 2
Key 3
Key 4
Table has no fixed length, no pre-declared size, no initialized table is nil
7. Function type
This type is very cool, and matlab inside the function is very similar, first function can be similar to the application of the transfer, and then function can be directly passed as functions parameters
function Fibonaccia (n)
if n = = 0 or n==1 Then
Return 1
Else
Return Fibonaccia (n-1) +fibonaccia (n-2)
End
End
Print (Fibonaccia (10))
Fib=fibonaccia
Print (FIB (10))
function Funcpass (tab,fun)
For k,v in Pairs (tab) do
Print (Fun (v))
End
End
tab={1,2,3,4,5}
Funcpass (TAB,FIB)
Summary: LUA has 8 basic data types: Nil,number,string,table,function,boolean,thread,userdata
Lua Learning Note 1, basic data types