lua tutorial 06
2016-01-04 15:42
411 查看
运算符
1.算术运算符
2.关系运算符
3.逻辑运算符
5.其他运算符
.. 字符串连接运算符
# 单目运算符:取字符串或表的长度
1.算术运算符
+ | 加法 |
- | 减法 |
* | 乘法 |
/ | 除法 |
% | 取余 |
^ | 乘幂 |
- | 负号 |
unction printTxt( str,num ) print("通过"..str.."计算得到:"..num) end a = 10 b = 5 c = a + b printTxt("加法",c) c = a - b printTxt("减法",c) c = a * b printTxt("乘法",c) c = a / b printTxt("除法",c) c = a % b printTxt("取余",c) c = a ^ b printTxt("乘幂",c) c = -a printTxt("负号",c)
2.关系运算符
== | 等于 |
~= | 不等于 |
> | 大于 |
< | 小于 |
>= | 大于等于 |
<= | 小于等于 |
--关系运算符 function printTxt02(idx, txt ) print("Line"..idx.." - a "..txt.." b") end pt = printTxt02 a = 15 b = 10 if a == b then pt(1,"equal to") else pt(1,"not equal to") end if a ~= b then pt(2, "not equal to") else pt(2, "equal to") end if a < b then pt(3, "less than") else pt(3, "not less than") end if a > b then pt(4,"greater than") else pt(4,"not greater than") end if a >= b then pt(5,"greater than or equal to") else pt(5,"less than") end if a <= b then pt(6,"less than or equal to") else pt(6,"greater than") end
3.逻辑运算符
and | 与 && |
or | 或 || |
not | 非 ! |
--逻辑运算符 a = 10 b = 5 if (a > 0) and (b > 0) then print("a and b all greater than 0") else print("a or b all less than 0") end a = 10 b = -5 if a > 0 or b > 0 then print("a or b is greater than 0") else print("a and b all less than 0") end if not(a > 0) then print("a is less than 0") else print("a is greater or equal to 0") end
5.其他运算符
.. 字符串连接运算符
# 单目运算符:取字符串或表的长度
--其他运算符 a = "Hello " b = "Lua" c = a..b print(c) print(#c) tab = {1,2,3,4,5} print(#tab)
相关文章推荐
- lua tutorial 05
- lua tutorial 04
- sublime添加直接运行语言的方法
- lua tutorial 03
- lua tutorial 02
- lua tutorial 01
- Lua脚本语言入门
- Lua使用笔记
- lua脚本语言的学习-----------------lua栈操作
- Lua语法学习笔记
- lua模块的几种实现方式
- lua脚本语言的学习-----------------带参数的lua函数的传递
- lua脚本语言的学习-----------------如何实现c++无参数的函数在lua中调用
- lua脚本语言的学习-----------------VS2013如何编译lua脚本的三方库
- ngx_lua配置及应用
- 【转】说下lua使用场景
- ngx_lua应用最佳实践
- Lua脚本
- Lua基础之字符串(string)
- Lua基础之字符串(string)