2018-09-18 22:42:38 +02:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-09-22 02:36:33 +02:00
|
|
|
const MaxArgs = 65536
|
|
|
|
|
2019-07-22 23:21:20 +02:00
|
|
|
type (
|
|
|
|
Function = func(ctx context.Context, args ...Value) (Value, error)
|
|
|
|
|
|
|
|
Functions map[string]Function
|
|
|
|
|
|
|
|
Namespace interface {
|
|
|
|
Namespace(name string) Namespace
|
|
|
|
RegisterFunction(name string, fun Function) error
|
|
|
|
RegisterFunctions(funs Functions) error
|
|
|
|
RegisteredFunctions() []string
|
|
|
|
RemoveFunction(name string)
|
|
|
|
}
|
|
|
|
)
|
2018-09-18 22:42:38 +02:00
|
|
|
|
2018-09-22 02:36:33 +02:00
|
|
|
func ValidateArgs(args []Value, minimum, maximum int) error {
|
|
|
|
count := len(args)
|
|
|
|
|
|
|
|
if count < minimum || count > maximum {
|
|
|
|
return Error(
|
|
|
|
ErrInvalidArgumentNumber,
|
|
|
|
fmt.Sprintf(
|
|
|
|
"expected number of arguments %d-%d, but got %d",
|
|
|
|
minimum,
|
|
|
|
maximum,
|
|
|
|
len(args)))
|
2018-09-18 22:42:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|