• cerement
    link
    fedilink
    arrow-up
    13
    arrow-down
    1
    ·
    edit-2
    7 months ago

    return a and a or breturn a or b

    correction from @murtaza64

    • murtaza64@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      7 months ago

      You don’t need the and right? Can’t it just be return a or b

      This doesn’t work if a is falsy non-null actually

      • cerement
        link
        fedilink
        arrow-up
        1
        ·
        7 months ago

        it’s just return a and b or c is the closest Lua has to a ternary operator, but yes, for the above you could shorten it to return a or b (“or returns the first argument if true, otherwise second argument is returned”)