目錄
- 關鍵字
- 數學運算子
- 字串相接運算子
- 邏輯運算子
- 關係運算子
- bitwise 位元運算子
- Lua Functions
關鍵字
1 2 3 4
| and break do else elseif end false for function if in local nil not or repeat return then true until while
|
數學運算子
1 2 3 4 5 6
| 1 + 7 2 - 8 3 * 9 4 / 10 5 % 11 6 ^ 12
|
字串相接運算子
1
| str = "Hello" .. "World"
|
邏輯運算子
1 2 3 4 5 6
| true and true true and false true or true true or false false or false not true
|
關係運算子
1 2 3 4 5 6 7 8
| 111 == 111 222 ~= 222 300 > 400 300 < 400 400 >= 400 400 >= 401 400 <= 400 400 <= 399
|
bitwise 位元運算子
AND
1 2 3 4 5 6 7
| 3 & 5
算法: 00000011 & 00000101
00000001
|
OR
1 2 3 4 5 6 7
| 3 | 5
算法: 00000011 | 00000101
00000111
|
XOR
1 2 3 4 5 6 7
| 3 ~ 5
算法: 00000011 ~ 00000101
00000110
|
Right Shift
1 2 3 4 5
| 7 >> 1
算法: 0000 0111 0000 0011
|
Left Shift
1 2 3 4 5
| 7 << 1
算法: 0000 0111 0000 1110
|
NOT
Lua Functions
tonumber: 轉 整數 資料型態
1 2 3 4 5
| tonumber("12as") tonumber("12") tonumber(123.3) tonumber(1230.0) tonumber(1230)
|
tostring: 轉 字串 資料型態
1 2 3
| tostring("fafsaf!$") tostring(5606) tostring(125.15665)
|
type: 識別 資料型態
1 2 3 4 5 6 7 8
| a, b, c, d, e, f, g = 1, 2.3, "4", true, nil, {}, function() end type(a) type(b) type(c) type(d) type(e) type(f) type(g)
|
assert: 檢查 異常錯誤,會導致Script錯誤
1 2 3
| a, b, c, d, e, f, g = 1, 2.3, "4", true, nil, {}, function() end a = 1; assert(a == 1) a = 2; assert(a == 1, "變數a只能是1")
|
error: 異常錯誤訊息,會導致Script錯誤
1 2 3 4
| pos = {x = 1, y = 1, z = 1} if pos.x == 1 then error("座標X錯誤") end
|
setmetatable: 元表,這有點難,可以做成類似class
詳情 https://www.runoob.com/lua/lua-metatables.html
getmetatable: 返回對像元表
詳情 https://www.runoob.com/lua/lua-metatables.html
print: 打印任何資料在控制台
log: 在遊戲路徑/bin/script.log 打印任何資料