From 3f78748ef357cbb128c96d7a07866f0953be1792 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 22 Jun 2007 12:33:54 -0300 Subject: traceback function moved to auxlib --- lua.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'lua.c') diff --git a/lua.c b/lua.c index c8951a1f..7d4f7b59 100644 --- a/lua.c +++ b/lua.c @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.164 2006/10/10 17:40:17 roberto Exp roberto $ +** $Id: lua.c,v 1.165 2007/04/26 20:39:38 roberto Exp roberto $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -73,27 +73,14 @@ static int report (lua_State *L, int status) { } -static int gettraceback (lua_State *L) { - lua_getfield(L, LUA_GLOBALSINDEX, "debug"); - if (!lua_istable(L, -1)) return 0; - lua_getfield(L, -1, "traceback"); /* check 'debug.traceback' */ - if (!lua_isfunction(L, -1)) return 0; - return 1; /* there is a function 'debug.traceback' */ -} - - static int traceback (lua_State *L) { - if (lua_isnoneornil(L, 1)) /* no error object? */ - return 1; /* keep it that way */ - if (!gettraceback(L)) /* no 'debug.traceback' function? */ - lua_pushvalue(L, 1); /* keep original message */ - else { - lua_pushvalue(L, 1); /* pass error message */ - lua_pushinteger(L, 2); /* skip this function and traceback */ - lua_call(L, 2, 1); /* call traceback */ + const char *msg = lua_tostring(L, 1); + if (msg) + luaL_traceback(L, L, msg, 2); + else if (!lua_isnoneornil(L, 1)) { /* is there an error object? */ + if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */ + lua_pushliteral(L, "(no error message)"); } - if (!lua_isstring(L, -1) && !luaL_callmeta(L, 1, "__tostring")) - lua_pushliteral(L, "(no error message)"); return 1; } -- cgit v1.2.3-55-g6feb