[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Evaluating expressions, not statements?
- From: Edgar Toernig <froese@...>
- Date: Fri, 06 Apr 2001 04:34:22 +0200
Roberto Ierusalimschy wrote:
> > The problem with this is that I can't see a way to check if the expression
> > evaluates to nil or that dostring() simply returns nil because of an error.
> You can check the 2o result from dostring (it returns an error code when
> there is an error).
You can't :-(
IMHO the API for dostring (and dofile and call) is broken. The only
thing guarantied is that in case of an error you get the two results
nil and a string. But whether this two values are in fact generated
by the system to signal an error or are the actual return values of
the executed code is not visible. And the userdata you get if the
code returned nothing is strange too. A simple 1 would work just as
In Sol I've changed these three function to always return a status as
the first result - nil if there was no error or a string describing the
error. The remaining results are that returned from the executed code.
PS: Another thing: dostring and dofile internally generate a function
object from the source and then execute it. Why not split this up and
have the functions compilestring/compilefile that return this function?
Would make your nice trick of precompiled strings even easier and could
be used even for files ;-)