注释
--[[
--]]
解除注释
---[[
--]]
a ,b = 10, 2*x
交换
x, y = y, x
a, b, c = 0, 1
print(a,b,c) -->0 1 nil
a, b, c = 0
print(a,b,c) -->nil nil 0
lua将false和nil视为假,除此之外任何值都视为真
and
如果第一个操作数为假则返回第一个操作数,不然返回第二个操作数
print(4 and 5) -->5
print(false and 5) -->false
or
如果第一个操作数为真就返回第一个操作数 ,不然返回第二个操作数
关联数组table
a = {}
k = "x"
a[k] = 10
a[20] = "great"
a["x"] <==> a.x
删除关联数组引用 a = nil
table永远都是匿名的,只存在引用
table没有引用时,garbage自动删除table
块
do
............
end
控制结构
if condition then
...
elseif
...
else
...
end
while cndition do
...
end
repeat
...
until !condition
for var = exp1,exp2,exp3 do
<>
end
exp1,exp2,exp3 初值 终值 步长
for i = 1,f(x) do <> end
中的f(x)只执行一次
for i,val in ipairs(a) do
print(val)
end