Error catching

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Error catching

Jakab
	We are currently evaluating whether to use Lua as our scripting
language for Star Wars Galaxies. One problem we have found is that Lua
doesn't seem to catch what we consider significant errors in a script. If a
divide by 0 happens, the result is set to +inf; if an array-out-of-bounds
access happens, the result is set to nil. Is there any way to have Lua pass
these results back as an error condition to the calling C code instead
(without changing the Lua source code)?

Steve Jakab
Verant

Reply | Threaded
Open this post in threaded view
|

Re: Error catching

Steve Dekorte-4
Jakab, Steve wrote:
> ...if an array-out-of-bounds 
> access happens, the result is set to nil. Is there any way to have Lua pass 
> these results back as an error condition to the calling C code instead 
> (without changing the Lua source code)? 

The array-out-of-bounds can be handled within lua using the "index" tag.

See: http://www.tecgraf.puc-rio.br/lua/manual/manual.html#4.8

Steve


Reply | Threaded
Open this post in threaded view
|

Re: Error catching

Reuben Thomas-3
On Fri, 26 Jan 2001, Steve Dekorte wrote:

>
> Jakab, Steve wrote:
> > ...if an array-out-of-bounds
> > access happens, the result is set to nil. Is there any way to have Lua pass
> > these results back as an error condition to the calling C code instead
> > (without changing the Lua source code)?
>
> The array-out-of-bounds can be handled within lua using the "index" tag.
>
> See: http://www.tecgraf.puc-rio.br/lua/manual/manual.html#4.8

As for the division behaviour, that's completely standard (according to IEEE
rules), but easily changed, assuming you have fenv.h on your system: you
just need to change the floating point exception state of the program
hosting Lua, using fesetexcept flag. If you can't do this you're on your
own, and may have to change the Lua source (but that's easy).

-- 
http://sc3d.org/rrt/ | computation, n.  automated pedantry


Reply | Threaded
Open this post in threaded view
|

Re: Error catching

Luiz Henrique de Figueiredo
In reply to this post by Steve Dekorte-4
>As for the division behaviour, that's completely standard (according to IEEE
>rules), but easily changed, assuming you have fenv.h on your system: you
>just need to change the floating point exception state of the program
>hosting Lua, using fesetexcept flag.

fenv.h seems to be standard in C99, but not in C89 or POSIX.
(However, it is present in recent Linux distributions.)
So, there's nothing we can do to the Lua code, if we want to keep it portable.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Error catching

Reuben Thomas-3
> >As for the division behaviour, that's completely standard (according to IEEE
> >rules), but easily changed, assuming you have fenv.h on your system: you
> >just need to change the floating point exception state of the program
> >hosting Lua, using fesetexcept flag.
>
> fenv.h seems to be standard in C99, but not in C89 or POSIX.
> (However, it is present in recent Linux distributions.)
> So, there's nothing we can do to the Lua code, if we want to keep it portable.

I meant to imply this: it's the original poster's problem (unfortunately).

-- 
http://sc3d.org/rrt/ | perfect, a.  unsatirizable