Expr's functions now support parameters with default value

This commit is contained in:
2024-06-01 19:56:40 +02:00
parent f66cd1fdb1
commit 9bba40f155
12 changed files with 180 additions and 247 deletions
+9 -5
View File
@@ -59,12 +59,16 @@ func (functor *golangFunctor) Invoke(ctx ExprContext, name string, args []any) (
// ---- Linking with Expr functions
type exprFunctor struct {
baseFunctor
params []string
params []ExprFuncParam
expr Expr
defCtx ExprContext
}
func newExprFunctor(e Expr, params []string, ctx ExprContext) *exprFunctor {
// func newExprFunctor(e Expr, params []string, ctx ExprContext) *exprFunctor {
// return &exprFunctor{expr: e, params: params, defCtx: ctx}
// }
func newExprFunctor(e Expr, params []ExprFuncParam, ctx ExprContext) *exprFunctor {
return &exprFunctor{expr: e, params: params, defCtx: ctx}
}
@@ -79,12 +83,12 @@ func (functor *exprFunctor) Invoke(ctx ExprContext, name string, args []any) (re
if funcArg, ok := arg.(Functor); ok {
// ctx.RegisterFunc(p, functor, 0, -1)
paramSpecs := funcArg.GetParams()
ctx.RegisterFunc(p, funcArg, typeAny, paramSpecs)
ctx.RegisterFunc(p.Name(), funcArg, typeAny, paramSpecs)
} else {
ctx.UnsafeSetVar(p, arg)
ctx.UnsafeSetVar(p.Name(), arg)
}
} else {
ctx.UnsafeSetVar(p, nil)
ctx.UnsafeSetVar(p.Name(), nil)
}
}
result, err = functor.expr.eval(ctx, false)