[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: allowing value evaluations as statements
- From: Rici Lake <lua@...>
- Date: Sun, 31 Dec 2006 22:36:28 -0500
On 31-Dec-06, at 9:56 PM, askok@dnainternet.net wrote:
A perl-ish way of making error checking, but neat and effective:
_= nsfm:fileExistsAtPath(testfile)
or error "File doesn't exist!"
_= nsfm:copyPath( testfile, newfile )
or error "File copy failed!"
Currently, Lua does not allow leaving the "_=" away, since that would
make these commands and commands don't have a value ('or' gives this a
value).
In my opinion, evaluation results could be allowed even if the value
is not stored anyway. In a way, they would have a "drain" that eats
up the value.
I do know that by a function this can be overcome, but the neaty is to
have the essential thing first (the command), and ability to switch
on/off the error check by simply commenting that out. Anyways, this
is caused by my exposure to perl lately, it does show. Perl has a lot
of those thisandthat or die things.. Which I actually like(d).
But what's wrong with:
assert(nsfm:fileExistsAtPath(testfile), "File doesn't exist!")
Or even, if fileExistsAtPath follows normal Lua conventions of
returning <nil/false, error message>,
assert(nsfm:fileExistsAtPath(testfile))
?
Another (perhaps warped) possibility is:
repeat until nsfm:fileExistsAtPath(testfile)
or Shriek "File doesn't exist"