commit 6f54b07663c48c6f306e93844598b509c2db444f
parent 741ad97e924086e9c2c55d4dcbb2cf1cc429a705
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 10 Dec 2014 09:31:07 -0200
give preference to global names in tracebacks
Diffstat:
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.275 2014/11/21 12:17:58 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.276 2014/12/08 15:26:09 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -83,20 +83,18 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
static void pushfuncname (lua_State *L, lua_Debug *ar) {
- if (*ar->namewhat != '\0') /* is there a name? */
- lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name);
+ if (pushglobalfuncname(L, ar)) { /* try first a global name */
+ lua_pushfstring(L, "function '%s'", lua_tostring(L, -1));
+ lua_remove(L, -2); /* remove name */
+ }
+ else if (*ar->namewhat != '\0') /* is there a name from code? */
+ lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */
else if (*ar->what == 'm') /* main? */
lua_pushliteral(L, "main chunk");
- else if (*ar->what == 'C') {
- if (pushglobalfuncname(L, ar)) {
- lua_pushfstring(L, "function '%s'", lua_tostring(L, -1));
- lua_remove(L, -2); /* remove name */
- }
- else
- lua_pushliteral(L, "?");
- }
- else
+ else if (*ar->what != 'C') /* for Lua functions, use <file:line> */
lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
+ else /* nothing left... */
+ lua_pushliteral(L, "?");
}