lua-users home
lua-l archive

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


> [...] 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.