xgo/objects/builtin_function.go

48 lines
1.1 KiB
Go
Raw Normal View History

2019-01-09 10:17:42 +03:00
package objects
import (
2019-01-11 13:27:28 +03:00
"github.com/d5/tengo/compiler/token"
2019-01-09 10:17:42 +03:00
)
// BuiltinFunction represents a builtin function.
2019-01-10 06:07:03 +03:00
type BuiltinFunction struct {
Name string
2019-01-17 12:56:05 +03:00
Value CallableFunc
2019-01-10 06:07:03 +03:00
}
2019-01-09 10:17:42 +03:00
// TypeName returns the name of the type.
2019-01-10 06:07:03 +03:00
func (o *BuiltinFunction) TypeName() string {
return "builtin-function:" + o.Name
2019-01-09 10:17:42 +03:00
}
2019-01-10 06:07:03 +03:00
func (o *BuiltinFunction) String() string {
2019-01-09 10:17:42 +03:00
return "<builtin-function>"
}
// BinaryOp returns another object that is the result of
// a given binary operator and a right-hand side object.
2019-01-10 06:07:03 +03:00
func (o *BuiltinFunction) BinaryOp(op token.Token, rhs Object) (Object, error) {
2019-01-09 10:17:42 +03:00
return nil, ErrInvalidOperator
}
// Copy returns a copy of the type.
2019-01-10 06:07:03 +03:00
func (o *BuiltinFunction) Copy() Object {
return &BuiltinFunction{Value: o.Value}
2019-01-09 10:17:42 +03:00
}
// IsFalsy returns true if the value of the type is falsy.
2019-01-10 06:07:03 +03:00
func (o *BuiltinFunction) IsFalsy() bool {
2019-01-09 10:17:42 +03:00
return false
}
// Equals returns true if the value of the type
// is equal to the value of another object.
2019-01-10 06:07:03 +03:00
func (o *BuiltinFunction) Equals(x Object) bool {
2019-01-09 10:17:42 +03:00
return false
}
2019-01-10 06:07:03 +03:00
// Call executes a builtin function.
2019-01-10 06:07:03 +03:00
func (o *BuiltinFunction) Call(args ...Object) (Object, error) {
return o.Value(args...)
}