By default, primer uses the debug.traceback
function as the error handler when it uses pcall.
This means that lua errors which primer encounters will be nicely formatted
for you by the time they are returned as primer::error.
If you want to use a customized error handler, there is a simple interface
that you can use to install one. Primer will then use it everywhere that
it makes protected calls. (Note: It must be installed once for each lua_State that you will use it with.)
// Push the current error handler to top of stack. Default is debug.traceback. inline int get_error_handler(lua_State * L) noexcept; // Set a new error handler. Pops one object from top of stack. inline void set_error_handler(lua_State * L) noexcept;
primer::protected_call is a wrapper over lua_pcall. It is the same, except that
it uses primer::get_error_handler to provide the error
handler. Primer always uses protected_call
internally rather than calling lua_pcall
directly.
// Simplified version of lua_pcall which handles setting up the error handler, // and removing it after the pcall returns. // Otherwise it is the same as pcall -- leaves any results / errors on top // of the stack. inline int protected_call(lua_State * L, int narg, int nret) noexcept;