类似于shell, 通过关键字确定区分,还好不是像py那样用空格 :)
没有标点符号
dofile调试
dofile(“lib1.lua”) – load your library
n = norm(3.4, 1.0)
print(twice(n)) –> 7.0880180586677
最好不要使用下划线加大写字母的标示符
字符串连接 ..
字符串转数字 tonumber()
1 | print(tostring(10) == "10") --> true |
命令行运行lua
- 在运行以前,Lua 使用所有参数构造 arg 表。脚本名索引为 0,脚本的参数从 1 开始
增加。脚本前面的参数从-1 开始减少。
Lua 是动态类型语言,变量不要类型定义
[[ ]] 使用表示 R”
1 | page = [[ |
字符串连接 ..
字符串转数字 tonumber()
1 | print(tostring(10) == "10") --> true |
列表
a = {[?]=?, [?]=?}
赋值
a, b = b, a
局部作用域
1 | do |
高频控制语句
1 | if cond then |
反向构造数据
1 | days = {"Sunday", "Monday", "Tuesday", "Wednesday", |
4.4 break return
误区
在控制结构的条件中除了 false 和 nil 为假,其他值都为真。所以 Lua 认为 0 和空串都是真
疑问
1 | polyline = {color="blue", thickness=2, npoints=4, {x=0, y=0}, |