(一)多变量赋值
--多变量赋值
a,c,d="1",13,true
print(a)--1
print(c)--13
print(d)--true
--多变量赋值时,如果值的个数不够变量的个数,变量为空
a,c,d="1",13
print(a)--1
print(c)--13
print(d)--nil
--多变量赋值时,如果值的个数多了,值会自动舍弃,只会有几个变量赋几个值
a,c,d="1",13,14,17
print(a)--1
print(c)--13
print(d)--14
(二)多返回值
function f1()
return 11,13,14,17
end
a,c,d=f1()
--多返回值是,你用几个变量接,就有几个值
print(a,c,d)--11,13,14
(三)三目运算
and or,不仅可以连接boolean,还可以连接其他的类型
在lua中只有nil和false才认为是假
and or也是短路操作,
--and or
print(1 and 3)--3
print(1 and nil)--nil,有假则假
print(1 or 3)--1,有真则真
print(1 or nil)--1
print(nil or false)--false
--三目运算符
x=3
y=4
--返回最大的那个值
local result=(x>y) and x or y
print(result)--4
--解析
--[[
(x>y) and x--->(x>y)
(x>y) or y----->y
result=4
]]