lua-users home
lua-l archive

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

>This may be fine when creating a co-routine from
>a Lua context. But I am calling lua_newthread from
>a C context. Does that mean I should call lua_newthread
>through lua_pcall if I am to prevent my application
>from exiting on an error? If so, what other Lua API
>functions should be treated with similar caution?

In C anything can happen. Any errors that occur "outside" the Lua virtual
machine cannot be reported to the host program. Until Lua 4.0 (inclusive),
Lua called "exit" when facing such errors. Lua 5.0 allows you to register your
own panic function (but you cannot return to Lua after this; Lua will exit if
you do). Lua 5.0 also introduced lua_cpcall to run C functions in protected
mode. One use of this is exactly to run C code and still catch any errors
gracefully. The interpreter lua.c uses this mechanism.

Bottom line: start your Lua transactions in the host program with a C function
that is called via lua_cpcall and don't worry about errors (except that you
have to catch them only once, after the call to lua_cpcall). See lua.c in
Lua 5.0 (beta).