Lupus590

lua's `and` and `or` reimplemented in lua

May 7th, 2021
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. local function isTruthy(arg) --[[ could be shortened as
  2.   if arg then
  3.     return true
  4.   else
  5.     return false
  6.   end ]]
  7.   if arg == nil then
  8.     return false
  9.   elseif arg == false then -- Could have used or if we were not dong this to redefine things
  10.     return false
  11.   else
  12.     return true
  13.   end
  14. end
  15.  
  16. local function Or(left, right)
  17.   if isTruthy(left) then
  18.     return left
  19.   else
  20.     return right
  21.   end
  22. end
  23.  
  24. local function And(left, right)
  25.   if isTruthy(left) then
  26.     return right
  27.   else
  28.     return left
  29.   end
  30. end
Add Comment
Please, Sign In to add comment