Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 627 Bytes

File metadata and controls

31 lines (22 loc) · 627 Bytes

Conditional Expression

The ternary ?: operator requires a helper because Lua has no equivalent single expression.

int max = a > b ? a : b;
local max = SF__.Ternary__((a > b), a, b)

The SF__.Ternary__ helper is emitted once when any ternary expression is used:

function SF__.Ternary__(cond, a, b)
    if cond then return a else return b end
end

Nested Ternary

Nested ternary expressions work because each is wrapped in a SF__.Ternary__ call:

int v = a > 0 ? (b > 0 ? 1 : 2) : 3;
local v = SF__.Ternary__((a > 0), SF__.Ternary__((b > 0), 1, 2), 3)