一.縮進
lua腳本無縮進但是有end結尾
二.邏輯判斷
if false or nil then
print("至少有一個是 true")
else
print("false 和 nil 都為 false")
end
if 0 then
print("數字 0 是 true")
else
print("數字 0 為 false")
end
三.算術操作
#在對一個數字字串上進行算術操作時,Lua 會嘗試將這個數字字串轉成一個數字
四.獲取字串的長度
#字串變數
五.for回圈
1.普通回圈
for var=exp1,exp2,exp3 do
<執行體>
end
2.死回圈
while( true )
do
print("回圈將永遠執行下去")
end
3.類似python中continue
方法一
for i = 10, 1, -1 do
repeat
if i == 5 then
print("continue code here")
break
end
print(i, "loop code here")
until true
end
方法 二
for i=1, 3 do
if i <= 2 then
print(i, "yes continue")
goto continue
end
print(i, " no continue")
::continue::
print([[i'm end]])
end
六.方法的定義
optional_function_scope function function_name( argument1, argument2, argument3..., argumentn)
function_body
return result_params_comma_separated
end
optional_function_scope: 該引數是可選的制定函式是全域函式還是區域函式,未設定該引數默認為全域函式,如果你需要設定函式為區域函式需要使用關鍵字 local,
function_name: 指定函式名稱,
argument1, argument2, argument3..., argumentn: 函式引數,多個引數以逗號隔開,函式也可以不帶引數,
function_body: 函式體,函式中需要執行的代碼陳述句塊,
result_params_comma_separated: 函式回傳值,Lua語言函式可以回傳多個值,每個值以逗號隔開,
七.匯入模塊
require "<模塊名>"
八.獨有的表結構
https://www.runoob.com/lua/lua-tables.html
九.類
https://www.runoob.com/lua/lua-object-oriented.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/170806.html
標籤:其他
