func ExampleWithEnvironment() {
	env := makeEnv() // Create evaluation environment
	result, panik, compileErrs := eval.EvalEnv(`fmt.Sprintf("%s %d", constant1, add(var1, 1) + 1)`, env)
	_ = panik
	_ = compileErrs
	fmt.Printf("%+v\n", result[0].Interface())
}
示例#2
0
文件: debug.go 项目: willf/godebug
// goEval runs eval.EvalEnv in a new goroutine. This is a quick hack to
// keep the debugger from pausing while running eval.EvalEnv.
func goEval(expr string, env eval.Env) (result []reflect.Value, panik error, compileErrors []error) {
	c := make(chan struct{})
	go func() {
		defer close(c)
		result, panik, compileErrors = eval.EvalEnv(expr, env)
	}()
	<-c
	return
}
示例#3
0
// goEval runs eval.EvalEnv in a new goroutine. This is a quick hack to
// keep the debugger from pausing while running eval.EvalEnv.
// It is also used to recover from panics in the eval library.
func goEval(expr string, env eval.Env) (result []reflect.Value, panik error, compileErrors []error) {
	c := make(chan struct{})
	go func() {
		defer func() {
			if r := recover(); r != nil {
				panik = fmt.Errorf("%v", r)
			}
			close(c)
		}()
		result, panik, compileErrors = eval.EvalEnv(expr, env)
	}()
	<-c
	return
}