diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-04-03 15:31:22 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-04-03 15:31:22 -0300 |
| commit | 3dd8ea54daa77345a8f193e871f6792722d8e131 (patch) | |
| tree | cc60485872b1d79774f1866446fa7a355ca0c87d | |
| parent | 620f49a7aae8a5c982b21f0accbf2ff9019a55f6 (diff) | |
| download | lua-3dd8ea54daa77345a8f193e871f6792722d8e131.tar.gz lua-3dd8ea54daa77345a8f193e871f6792722d8e131.tar.bz2 lua-3dd8ea54daa77345a8f193e871f6792722d8e131.zip | |
Order change in 'pushfuncname'
'pushglobalfuncname' can be quite slow (as it traverses all globals and
all loaded modules), so try first to get a name from the code.
| -rw-r--r-- | lauxlib.c | 10 | ||||
| -rw-r--r-- | testes/db.lua | 4 |
2 files changed, 7 insertions, 7 deletions
| @@ -94,14 +94,14 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { | |||
| 94 | 94 | ||
| 95 | 95 | ||
| 96 | static void pushfuncname (lua_State *L, lua_Debug *ar) { | 96 | static void pushfuncname (lua_State *L, lua_Debug *ar) { |
| 97 | if (pushglobalfuncname(L, ar)) { /* try first a global name */ | 97 | if (*ar->namewhat != '\0') /* is there a name from code? */ |
| 98 | lua_pushfstring(L, "function '%s'", lua_tostring(L, -1)); | ||
| 99 | lua_remove(L, -2); /* remove name */ | ||
| 100 | } | ||
| 101 | else if (*ar->namewhat != '\0') /* is there a name from code? */ | ||
| 102 | lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */ | 98 | lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */ |
| 103 | else if (*ar->what == 'm') /* main? */ | 99 | else if (*ar->what == 'm') /* main? */ |
| 104 | lua_pushliteral(L, "main chunk"); | 100 | lua_pushliteral(L, "main chunk"); |
| 101 | else if (pushglobalfuncname(L, ar)) { /* try a global name */ | ||
| 102 | lua_pushfstring(L, "function '%s'", lua_tostring(L, -1)); | ||
| 103 | lua_remove(L, -2); /* remove name */ | ||
| 104 | } | ||
| 105 | else if (*ar->what != 'C') /* for Lua functions, use <file:line> */ | 105 | else if (*ar->what != 'C') /* for Lua functions, use <file:line> */ |
| 106 | lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); | 106 | lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); |
| 107 | else /* nothing left... */ | 107 | else /* nothing left... */ |
diff --git a/testes/db.lua b/testes/db.lua index 3c821ab7..8e13373c 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
| @@ -701,7 +701,7 @@ assert(debug.traceback(print, 4) == print) | |||
| 701 | assert(string.find(debug.traceback("hi", 4), "^hi\n")) | 701 | assert(string.find(debug.traceback("hi", 4), "^hi\n")) |
| 702 | assert(string.find(debug.traceback("hi"), "^hi\n")) | 702 | assert(string.find(debug.traceback("hi"), "^hi\n")) |
| 703 | assert(not string.find(debug.traceback("hi"), "'debug.traceback'")) | 703 | assert(not string.find(debug.traceback("hi"), "'debug.traceback'")) |
| 704 | assert(string.find(debug.traceback("hi", 0), "'debug.traceback'")) | 704 | assert(string.find(debug.traceback("hi", 0), "'traceback'")) |
| 705 | assert(string.find(debug.traceback(), "^stack traceback:\n")) | 705 | assert(string.find(debug.traceback(), "^stack traceback:\n")) |
| 706 | 706 | ||
| 707 | do -- C-function names in traceback | 707 | do -- C-function names in traceback |
| @@ -829,7 +829,7 @@ end | |||
| 829 | 829 | ||
| 830 | co = coroutine.create(function (x) f(x) end) | 830 | co = coroutine.create(function (x) f(x) end) |
| 831 | a, b = coroutine.resume(co, 3) | 831 | a, b = coroutine.resume(co, 3) |
| 832 | t = {"'coroutine.yield'", "'f'", "in function <"} | 832 | t = {"'yield'", "'f'", "in function <"} |
| 833 | while coroutine.status(co) == "suspended" do | 833 | while coroutine.status(co) == "suspended" do |
| 834 | checktraceback(co, t) | 834 | checktraceback(co, t) |
| 835 | a, b = coroutine.resume(co) | 835 | a, b = coroutine.resume(co) |
