Skip to content

Instantly share code, notes, and snippets.

@dealingwith
Last active August 29, 2015 14:14
Show Gist options
  • Save dealingwith/f135e9883cb697063c8c to your computer and use it in GitHub Desktop.
Save dealingwith/f135e9883cb697063c8c to your computer and use it in GitHub Desktop.
functional if in Lua
function print_true()
print("true")
end
function print_false()
print("false")
end
function fif(val, a, b)
if val then a() else b() end
end
function fif_flip(val, a, b)
if val then a() else b() end
return not val
end
fif(true, print_true, print_false) -- prints "true"
var x = fif_flip(false, print_true, print_false) -- prints "false", returns true
-- x is true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment