I still find the syntax for complex string inspection befuddling, so I’m hoping I can get some help with this issue.
Basically I need to compare the locations that two different commands are coming from. I get this info using debug.traceback()
.
For example, here’s a typical output from print(debug.traceback())
:
stack traceback:
SimpleButtons:178: in function 'button'
greetingScreen:31: in function 'greetingScreen'
Main:16: in global '_wrap_draw'
SupportedOrientation :260: in function <SupportedOrientation :242>
As you can see, each level of the stack reports the tab it was called from, then the line number it was called from, and finally the function it was called from.
So here’s the situation I’m confronting: I have a current traceback that I need to compare to a table of stored tracebacks. I need to find the value in the table that most closely matches the current traceback.
My idea is to break each traceback string into a table of subtables, with each subtable breaking down the data in one level of the stack. I guess that means that what I need to know how to do is:
- examine each line after “stack traceback” one by one
- get the substring before the first colon
- get the substring between the first and second colons
- get the substring that’s between two delimiting characters, which can be either single quotes or brackets, at the end of the line
So, for instance, with that knowledge I could turn the above traceback into this:
currentTraceback = {
{“SimpleButtons”, ”178”, “button”},
{“greetingScreen”, “31”, “greetingScreen”},
{“Main”, “16”, “_wrap_draw”},
{“SupportedOrientation”, “260”, “<SupportedOrientation :242>“}
}
…then, I think, it would be easy to compare each line of the current traceback to the equivalent line in a stored table of tracebacks.
…is there a substring wizard out there who can help me figure this out?