mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
22382a0f61
* Added namespace builder * Fixed linting issues * Added extra check * Updated e2e lib * Renamed NamespaceBuilder to NamespaceContainer and changed func receivers * Renamed NewLib to RegisterLib
39 lines
695 B
Go
39 lines
695 B
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
const MaxArgs = 65536
|
|
|
|
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)
|
|
}
|
|
)
|
|
|
|
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)))
|
|
}
|
|
|
|
return nil
|
|
}
|