yaegi icon indicating copy to clipboard operation
yaegi copied to clipboard

Capture call stack

Open tigerwill90 opened this issue 5 years ago • 0 comments

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.

tigerwill90 avatar Feb 18 '21 15:02 tigerwill90