Wednesday, November 23, 2011

Return if

I'd quite like a return-if construction in lua, or at least I'd like to experiment with one.

It would have the form of something like

<return if>  :=  <opt-whitespace> <if> <opt-whitespace> <function>

Then you could do things like

function someFunction()
    local everyThingHasGoneWrong()

    // code
    return if everythingHasGoneWrong()
    // more code
    return if everyThingHasGoneWrong()

The first return arg would be a bool for the if, the second and all those after would be the returns. I'm sure there would be some interesting recursive snippets you could do.