mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
lualib: allow to replace error handling function
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
3f259d0ed2
commit
3739aabda1
2 changed files with 25 additions and 11 deletions
|
@ -25,6 +25,9 @@
|
|||
#include <lauxlib.h>
|
||||
#include "common/util.h"
|
||||
|
||||
/** Lua function to call on dofuction() error */
|
||||
lua_CFunction lualib_dofunction_on_error;
|
||||
|
||||
#define luaA_checkfunction(L, n) \
|
||||
do { \
|
||||
if(!lua_isfunction(L, n)) \
|
||||
|
@ -79,17 +82,9 @@ luaA_absindex(lua_State *L, int ud)
|
|||
static inline int
|
||||
luaA_dofunction_error(lua_State *L)
|
||||
{
|
||||
if(!luaL_dostring(L, "return debug.traceback(\"error while running function\", 3)"))
|
||||
{
|
||||
/* Move traceback before error */
|
||||
lua_insert(L, -2);
|
||||
/* Insert sentence */
|
||||
lua_pushliteral(L, "\nerror: ");
|
||||
/* Move it before error */
|
||||
lua_insert(L, -2);
|
||||
lua_concat(L, 3);
|
||||
}
|
||||
return 1;
|
||||
if(lualib_dofunction_on_error)
|
||||
return lualib_dofunction_on_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Execute an Lua function on top of the stack.
|
||||
|
|
19
luaa.c
19
luaa.c
|
@ -680,6 +680,22 @@ luaA_panic(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
luaA_dofunction_on_error(lua_State *L)
|
||||
{
|
||||
if(!luaL_dostring(L, "return debug.traceback(\"error while running function\", 3)"))
|
||||
{
|
||||
/* Move traceback before error */
|
||||
lua_insert(L, -2);
|
||||
/* Insert sentence */
|
||||
lua_pushliteral(L, "\nerror: ");
|
||||
/* Move it before error */
|
||||
lua_insert(L, -2);
|
||||
lua_concat(L, 3);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Initialize the Lua VM
|
||||
* \param xdg An xdg handle to use to get XDG basedir.
|
||||
*/
|
||||
|
@ -706,6 +722,9 @@ luaA_init(xdgHandle* xdg)
|
|||
/* Set panic function */
|
||||
lua_atpanic(L, luaA_panic);
|
||||
|
||||
/* Set error handling function */
|
||||
lualib_dofunction_on_error = luaA_dofunction_on_error;
|
||||
|
||||
luaL_openlibs(L);
|
||||
|
||||
luaA_fixups(L);
|
||||
|
|
Loading…
Reference in a new issue