lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Jul 1, 2011 at 01:08, steve donovan <steve.j.donovan@gmail.com> wrote:
> On Fri, Jul 1, 2011 at 8:42 AM, steve donovan <steve.j.donovan@gmail.com> wrote:
>> [1] http://lua-users.org/wiki/ExpressionsAsStatements
>
> I must share one gem from that page, from the ever-prolific Rici Lake:
>
> repeat until nsfm:fileExistsAtPath(testfile) or Shriek "File doesn't exist"
>
> The 'repeat until' is a mouthful, but giving it a new name is a good
> job for a preprocessor.
>
> [snip]
>
> steve d.
>
>

At that point we're not far from:
> try assert(doSomething()) catch e handle_error(e) end

compared to:
> repeat until doSomething() or handle_error('oh no')

or:
> local r, e = pcall(doSomething); r = r or handle_error(e)

try/catch is one thing I've often missed in Lua... using pcall instead
tends to be syntactically awkward.

-- 
Sent from my toaster.