Lua中的三目运算符

--lua 三目运算符

--Result = A = 0 ? A : B

local B = 1
local Calc = B * 100
local Result = (Calc == 0 and Calc) or 99

print(Result)




--Result = A == X ? B : C Within function

local List = 0
local function CallFalse()
	return false
end

local function CallTrue()
	return true
end

local Result = (List == 1 and {CallFalse()} or {CallTrue()})[1]  

print(Result)


你可能感兴趣的:(Lua中的三目运算符)