diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-01-10 15:21:10 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-01-10 15:21:10 -0200 |
commit | 0480ea088629122334df0e8d5557cb27c9232aa9 (patch) | |
tree | c4706db4923b45ca783b5e422aeb708fa11c432d /lua.c | |
parent | 162b66624d6868e71010ef3988b482fc811def34 (diff) | |
download | lua-0480ea088629122334df0e8d5557cb27c9232aa9.tar.gz lua-0480ea088629122334df0e8d5557cb27c9232aa9.tar.bz2 lua-0480ea088629122334df0e8d5557cb27c9232aa9.zip |
gets `debug.traceback' current when error occurs
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.133 2004/11/18 19:53:49 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.134 2005/01/10 16:30:59 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -79,10 +79,23 @@ static int report (lua_State *L, int status) { | |||
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | static int traceback (lua_State *L) { | ||
83 | luaL_getfield(L, LUA_GLOBALSINDEX, "debug.traceback"); | ||
84 | if (!lua_isfunction(L, -1)) | ||
85 | lua_pop(L, 1); | ||
86 | else { | ||
87 | lua_pushvalue(L, 1); /* pass error message */ | ||
88 | lua_pushinteger(L, 2); /* skip this function and traceback */ | ||
89 | lua_call(L, 2, 1); /* call debug.traceback */ | ||
90 | } | ||
91 | return 1; | ||
92 | } | ||
93 | |||
94 | |||
82 | static int docall (lua_State *L, int narg, int clear) { | 95 | static int docall (lua_State *L, int narg, int clear) { |
83 | int status; | 96 | int status; |
84 | int base = lua_gettop(L) - narg; /* function index */ | 97 | int base = lua_gettop(L) - narg; /* function index */ |
85 | luaL_getfield(L, LUA_GLOBALSINDEX, "debug.traceback"); | 98 | lua_pushcfunction(L, traceback); /* push traceback function */ |
86 | lua_insert(L, base); /* put it under chunk and args */ | 99 | lua_insert(L, base); /* put it under chunk and args */ |
87 | signal(SIGINT, laction); | 100 | signal(SIGINT, laction); |
88 | status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); | 101 | status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); |