aboutsummaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-06-22 12:33:54 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-06-22 12:33:54 -0300
commit3f78748ef357cbb128c96d7a07866f0953be1792 (patch)
treef24acd60228a0aed334c11b1db60cbadf3347ddf /lua.c
parentd26bfb5ae4fd11b784298317b39a390ea2a5beb5 (diff)
downloadlua-3f78748ef357cbb128c96d7a07866f0953be1792.tar.gz
lua-3f78748ef357cbb128c96d7a07866f0953be1792.tar.bz2
lua-3f78748ef357cbb128c96d7a07866f0953be1792.zip
traceback function moved to auxlib
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/lua.c b/lua.c
index c8951a1f..7d4f7b59 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.164 2006/10/10 17:40:17 roberto Exp roberto $ 2** $Id: lua.c,v 1.165 2007/04/26 20:39:38 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*/
@@ -73,27 +73,14 @@ static int report (lua_State *L, int status) {
73} 73}
74 74
75 75
76static int gettraceback (lua_State *L) {
77 lua_getfield(L, LUA_GLOBALSINDEX, "debug");
78 if (!lua_istable(L, -1)) return 0;
79 lua_getfield(L, -1, "traceback"); /* check 'debug.traceback' */
80 if (!lua_isfunction(L, -1)) return 0;
81 return 1; /* there is a function 'debug.traceback' */
82}
83
84
85static int traceback (lua_State *L) { 76static int traceback (lua_State *L) {
86 if (lua_isnoneornil(L, 1)) /* no error object? */ 77 const char *msg = lua_tostring(L, 1);
87 return 1; /* keep it that way */ 78 if (msg)
88 if (!gettraceback(L)) /* no 'debug.traceback' function? */ 79 luaL_traceback(L, L, msg, 2);
89 lua_pushvalue(L, 1); /* keep original message */ 80 else if (!lua_isnoneornil(L, 1)) { /* is there an error object? */
90 else { 81 if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */
91 lua_pushvalue(L, 1); /* pass error message */ 82 lua_pushliteral(L, "(no error message)");
92 lua_pushinteger(L, 2); /* skip this function and traceback */
93 lua_call(L, 2, 1); /* call traceback */
94 } 83 }
95 if (!lua_isstring(L, -1) && !luaL_callmeta(L, 1, "__tostring"))
96 lua_pushliteral(L, "(no error message)");
97 return 1; 84 return 1;
98} 85}
99 86