StackTracePlus icon indicating copy to clipboard operation
StackTracePlus copied to clipboard

STP.stacktrace not strictly compatible to debug.traceback

Open devurandom opened this issue 10 years ago • 2 comments
trafficstars

STP.stacktrace is not strictly compatible to debug.traceback: It returns two values, instead of one. This creates problems in conjunction with varargs functions and those created through the Lua C API (which will happily consume the additional argument, creating an unexpected stack layout).

Is this something you want to fix?

--- a/src/StackTracePlus.lua
+++ b/src/StackTracePlus.lua
@@ -391,7 +392,7 @@ Stack Traceback
                info = dumper.getinfo(level, "nSlf")
        end

-       return dumper:concat_lines(), original_error
+       return dumper:concat_lines()
 end

 --

devurandom avatar Nov 12 '15 18:11 devurandom

I'm not sure. Can't you just wrap it in a function to adjust the number of return values? Like,

debug.traceback = function(...) return (STP.stacktrace(...)) end

ignacio avatar Nov 12 '15 19:11 ignacio

As a compromise, provide STP.traceback (with name matching debug.traceback) that does exactly that?

Are there any cases where debug.traceback returns 0 or 2 values?

SoniEx2 avatar Nov 13 '17 02:11 SoniEx2