Expr's functions now support parameters with default value
This commit is contained in:
+9
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user