Files
yaegi/interp/example_eval_test.go
zeekay a6a6264f91 refactor: own the module path (github.com/hanzoai/yaegi)
Per the standing fork rule, a hanzoai fork declares its OWN module path and
is required directly -- never resolved via a `replace` against the upstream
path. Keeping the upstream path meant every import line in every consumer
carried the upstream brand.

  module github.com/traefik/yaegi -> module github.com/hanzoai/yaegi

Mechanical and behaviour-neutral: every occurrence is an import path
(package self-imports, cmd/, _test/ fixtures interpreted at test time, and
the guthib.com/<org>/{fromage,cheese,vin} fake vendor trees under
example/pkg, whose directory components were renamed in lockstep with the
import strings that reference them).

GOPATH-mode source-import tests (interp TestFile) resolve the module by its
path under $GOPATH/src, so the required checkout location moves with the
module path -- as README already documents. Verified green at
$GOPATH/src/github.com/hanzoai/yaegi.

LICENSE is untouched: "Copyright 2020 Traefik Labs SAS" is the Apache-2.0
attribution and is a legal obligation, not a brand leak.

Also drops the inherited CONTRIBUTING.md CLA clause, which named an
upstream agreement this fork does not administer.
2026-07-25 12:26:31 -07:00

39 lines
681 B
Go

package interp_test
import (
"fmt"
"log"
"github.com/hanzoai/yaegi/interp"
)
// Generic example.
func Example_eval() {
// Create a new interpreter context
i := interp.New(interp.Options{})
// Run some code: define a new function
_, err := i.Eval("func f(i int) int { return 2 * i }")
if err != nil {
log.Fatal(err)
}
// Access the interpreted f function with Eval
v, err := i.Eval("f")
if err != nil {
log.Fatal(err)
}
// Returned v is a reflect.Value, so we can use its interface
f, ok := v.Interface().(func(int) int)
if !ok {
log.Fatal("type assertion failed")
}
// Use interpreted f as it was pre-compiled
fmt.Println(f(2))
// Output:
// 4
}