mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
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.
50 lines
842 B
Go
50 lines
842 B
Go
package interp_test
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/hanzoai/yaegi/interp"
|
|
"github.com/hanzoai/yaegi/stdlib"
|
|
)
|
|
|
|
func ExampleInterpreter_self() {
|
|
i := interp.New(interp.Options{})
|
|
|
|
if err := i.Use(stdlib.Symbols); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if err := i.Use(interp.Symbols); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
_, err := i.Eval(`import (
|
|
"fmt"
|
|
"log"
|
|
|
|
// Import interp to gain access to Self.
|
|
"github.com/hanzoai/yaegi/interp"
|
|
)`)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
_, err = i.Eval(`
|
|
// Evaluate code directly.
|
|
fmt.Println("Hello Yaegi from Go")
|
|
|
|
// Evaluate code indirectly via the Self access point.
|
|
_, err := interp.Self.Eval("fmt.Println(\"Hello Yaegi from Yaegi\")")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
`)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Output:
|
|
//
|
|
// Hello Yaegi from Go
|
|
// Hello Yaegi from Yaegi
|
|
}
|