
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
github.com/rocky/go-eval
This project adds an eval() function to go.
Right now only, Go expressions are handled.
Right now the basic dance is a 4-step process.
go/parser
A skeletal structure is below:
package ...
import ("reflect"; "go/parser"; "github.com/0xfaded/eval")
...
env := &eval.Env {
Name: ".",
Vars: make(map[string] reflect.Value),
Consts: make(map[string] reflect.Value),
Funcs: make(map[string] reflect.Value),
Types: make(map[string] reflect.Type),
Pkgs : make(map[string] eval.Pkg),
}
// Populate env with a useful evaluation environment
line := `5 * 6 + int32(len("abc"[0:1])))` // something to eval
ctx := &eval.Ctx{line}
if expr, err := parser.ParseExpr(line); err != nil {
fmt.Printf("parse error: %s\n", err)
} else if cexpr, errs := eval.CheckExpr(ctx, expr, env); len(errs) != 0 {
for _, cerr := range errs {
fmt.Printf("%v\n", cerr)
}
} else if vals, _, err := eval.EvalExpr(ctx, cexpr, env); err != nil {
fmt.Printf("eval error: %s\n", err)
} else {
// do something with pointer to reflect.Value array vals, e.g.:
fmt.Println((*vals)[0].Interface())
}
The program repl.go is a full Go program showing this.
Right now, values are retuned as a pointer to an array of reflect.Value() and reflect.Values are used as intermediate results. However a callback to a conversion routine is provided for applications that need to use a different representation of a value. The gub debugger is an instance where this occurs.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.