function test(a)
a = a or 1
print(a)
end
test()
test(2)
console:
1
2
function test(a)
a = a or true
print(a)
end
test()
test(false)
两个居然 都 是true
判断 bool 类型时用这个方法。
function test()
a = a == nil and true or false
或者
a= a ~= false
print(a)
end