diff --git a/context.go b/context.go index d01c7d1..37fd1b9 100644 --- a/context.go +++ b/context.go @@ -4,6 +4,8 @@ // context.go package expr +type FuncTemplate func(ctx exprContext, name string, args []any) (result any, err error) + type exprFunc interface { Name() string MinArgs() int @@ -15,4 +17,5 @@ type exprContext interface { SetValue(varName string, value any) GetFuncInfo(name string) exprFunc Call(name string, args []any) (result any, err error) + RegisterFunc(name string, f FuncTemplate, minArgs, maxArgs int) } diff --git a/helpers.go b/helpers.go index f62e5f7..d524e2c 100644 --- a/helpers.go +++ b/helpers.go @@ -33,7 +33,7 @@ func EvalStringV(source string, args []EvalArg) (result any, err error) { for _, arg := range args { if isFunc(arg.value) { if f, ok := arg.value.(FuncTemplate); ok { - ctx.addFunc(arg.name, f) + ctx.RegisterFunc(arg.name, f, 0, -1) } else { err = fmt.Errorf("invalid function specification: %q", arg.name) } diff --git a/simple-func-store.go b/simple-func-store.go index 90b7593..cfd1d6e 100644 --- a/simple-func-store.go +++ b/simple-func-store.go @@ -3,8 +3,6 @@ package expr import "fmt" -type FuncTemplate func(ctx exprContext, name string, args []any) (result any, err error) - type SimpleFuncStore struct { varStore map[string]any funcStore map[string]FuncTemplate @@ -52,7 +50,7 @@ func (ctx *SimpleFuncStore) GetFuncInfo(name string) (f exprFunc) { return } -func (ctx *SimpleFuncStore) addFunc(name string, f FuncTemplate) { +func (ctx *SimpleFuncStore) RegisterFunc(name string, f FuncTemplate, minArgs, maxArgs int) { ctx.funcStore[name] = f } diff --git a/simple-var-store.go b/simple-var-store.go index 8f4e5dc..ae89a36 100644 --- a/simple-var-store.go +++ b/simple-var-store.go @@ -27,3 +27,6 @@ func (ctx *SimpleVarStore) GetFuncInfo(name string) (f exprFunc) { func (ctx *SimpleVarStore) Call(name string, args []any) (result any, err error) { return } + +func (ctx *SimpleVarStore) RegisterFunc(name string, f FuncTemplate, minArgs, maxArgs int) { +}