yaegi
yaegi copied to clipboard
Capture call stack
Proposal
It would be nice to be able to get the current call stack from a pre-compile function.
For example
const src = `package foo
import "github.com/johndoe/scenario"
func TestSomething(t *scenario.T) {
t.Error("fail")
}
`
type T struct {
interp *interp.Interpreter
}
func (t *T) Error(args ...interface{}) {
stacks := t.interp.CaptureCallStack(1)
for _, stack := range stacks {
fmt.Println("%s: %s", stack.Position(), fmt.Sprint(args...))
}
}
Background
It could allow to have more context on which code the interpreter executes.
Workarounds
As mentionned in #1037, I don't think there is a way to get the current call stack yet. To note that the function runCfg already print the position in case of panic.