Re[2]: Catching syntax errors.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re[2]: Catching syntax errors.

Steve Goodrich
     Wow, you're right. I thought I tried that but I guess I was doing 
     something wrong. 
     
     Thanks!
     
     Steve.


______________________________ Reply Separator _________________________________
Subject: Re: Catching syntax errors. 
Author:  [hidden email] at Address-InternetPO
Date:    1/22/98 1:09 PM


> [...] Is there anyway for the
> embedding program to be notified of syntax errors rather than just 
> printing them to standard error and calling exit().
     
Sure. Just set the error handler, with "lua_seterrormethod". This function 
sets the function to be called when any error ocurrs (such as syntax errors). 
A very naive way to do this follows:
     
  lua_pushnil();
  lua_seterrormethod();  /* set error method to nil -> does nothing on error */ 
  if (lua_dofile(filename) != 0) {
    /* an error happens when running the file */ 
    ...
     
  The new error method doesn't need to be nil. It can be any
function (in Lua or a lua_CFunction), for instace to catch the error 
message for future reference.
     
-- Roberto
     
PS: Lua never calls "exit()" when a syntax error occurs. Both "lua_dofile" 
and "lua_dostring" return a value signaling whether there was an error or 
not.