lua-users home
lua-l archive

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

>When Lua gets into a reall bad error (one for which no error handler is
>available) it calls exit.

We understand that killing the host program is not very polite, but what else
could it do when facing a real bad error? It cannot return to the application
because the state might be unusable after a memory allocation error.

Just to make it clear: Lua only calls exit when some error happens *outside*
the execution of a chunk. It does not need to be a bad error at all. It might
simply be lua_error called directly from C at the top level (that is, without
going through Lua). It might be trying to index an undefined variable or
something like this.

One simple way to avoid exits is to make sure that Lua is always called inside
an execution context, and this is simple to do by running your code as an
ordinary Lua function. In other words, in main do whatever initialization
is needed, including opening Lua, and then call a function to do the actual
work using lua_pushcfunction and lua_call(L,0,0).