-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Labels
Description
可以把常用的函数注册到引擎中,然后就能像内置函数一样在输入的数学表达式中使用。
e.g
engine.RegFunction("double", 1, func(expr ...engine.ExprAST) float64 {
return engine.ExprASTResult(expr[0]) * 2
})然后就可以在输入的表达式中使用这个函数 double:
exp := "double(6) + 2"
r, err := engine.ParseAndExec("double(6) + 2")
if err != nil {
panic(err)
}
fmt.Printf("double(6) + 2 = %f\n", r) // will print : double(6) + 2 = 14.000000