diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-10 09:31:32 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-10 09:31:32 -0200 |
commit | 6f54b07663c48c6f306e93844598b509c2db444f (patch) | |
tree | d25d405abf0abf2d7f9713c4a90809eeff5189fa /lauxlib.c | |
parent | 741ad97e924086e9c2c55d4dcbb2cf1cc429a705 (diff) | |
download | lua-6f54b07663c48c6f306e93844598b509c2db444f.tar.gz lua-6f54b07663c48c6f306e93844598b509c2db444f.tar.bz2 lua-6f54b07663c48c6f306e93844598b509c2db444f.zip |
give preference to global names in tracebacks
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.275 2014/11/21 12:17:58 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.276 2014/12/08 15:26:09 roberto Exp $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -83,20 +83,18 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { | |||
83 | 83 | ||
84 | 84 | ||
85 | static void pushfuncname (lua_State *L, lua_Debug *ar) { | 85 | static void pushfuncname (lua_State *L, lua_Debug *ar) { |
86 | if (*ar->namewhat != '\0') /* is there a name? */ | 86 | if (pushglobalfuncname(L, ar)) { /* try first a global name */ |
87 | lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); | 87 | lua_pushfstring(L, "function '%s'", lua_tostring(L, -1)); |
88 | lua_remove(L, -2); /* remove name */ | ||
89 | } | ||
90 | else if (*ar->namewhat != '\0') /* is there a name from code? */ | ||
91 | lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */ | ||
88 | else if (*ar->what == 'm') /* main? */ | 92 | else if (*ar->what == 'm') /* main? */ |
89 | lua_pushliteral(L, "main chunk"); | 93 | lua_pushliteral(L, "main chunk"); |
90 | else if (*ar->what == 'C') { | 94 | else if (*ar->what != 'C') /* for Lua functions, use <file:line> */ |
91 | if (pushglobalfuncname(L, ar)) { | ||
92 | lua_pushfstring(L, "function '%s'", lua_tostring(L, -1)); | ||
93 | lua_remove(L, -2); /* remove name */ | ||
94 | } | ||
95 | else | ||
96 | lua_pushliteral(L, "?"); | ||
97 | } | ||
98 | else | ||
99 | lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); | 95 | lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); |
96 | else /* nothing left... */ | ||
97 | lua_pushliteral(L, "?"); | ||
100 | } | 98 | } |
101 | 99 | ||
102 | 100 | ||