Documentation ¶
Overview ¶
Package Callable provides generic methods for working with callable functions.
Index ¶
- func ArgumentCount(fn Function) int
- func BoundArguments(fn Function) Array.Any
- func BoundArgumentsCount(fn Function) int
- func Cycle()
- func Defer(fn Function, args ...variant.Any)
- func Hash(fn Function) uint32
- func IsNil(fn Function) bool
- func IsProxy(fn Function) bool
- func IsStandard(fn Function) bool
- func IsValid(fn Function) bool
- func Method(fn Function) string
- func Receiver(fn Function) any
- type Function
- type Proxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArgumentCount ¶
ArgumentCount returns the total number of arguments this Callable should take.
func BoundArguments ¶
BoundArguments returns the arguments that have been bound to this Callable.
func BoundArgumentsCount ¶
BoundArgumentsCount returns the total amount of arguments bound (or unbound) via successive bind or unbind calls. If the amount of arguments unbound is greater than the ones bound, this function returns a value less than zero.
func Defer ¶
Defer calls the function represented by this callable at the end of the current frame. Arguments can be passed and should match the method's signature.
func Hash ¶
Hash returns the 32-bit hash value of this Callable's object.
Note: Callables with equal content will always produce identical hash values. However, the reverse is not true. Returning identical hash values does not imply the callables are equal, because different callables can have identical hash values due to hash collisions. The engine uses a 32-bit hash algorithm for hash.
func IsStandard ¶
IsStandard returns true if the given value is backed by a Go function.
Types ¶
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
Function represents a function. It can either be a method on a named type, or a custom callable used for different purposes
var Nil Function
Nil represents a nil function.
func Bind ¶
Bind returns a copy of this Callable with one or more arguments bound. When called, the bound arguments are passed after the arguments supplied by call. See also Unbind.
Note: When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.
func New ¶
New returns a new [Func] from the given value, if the value is not a Go func then it will be wrapped as if it were a function without any arguments that returns the specified value.
func Through ¶
func Through(proxy Proxy, state complex128) Function
func Unbind ¶
Unbind returns a copy of this Callable with a number of arguments unbound. In other words, when the new callable is called the last few arguments supplied by the user are ignored, according to argcount. The remaining arguments are passed to the callable. This allows to use the original callable in a context that attempts to pass more arguments than this callable can handle, e.g. a signal with a fixed number of arguments. See also Bind.
Note: When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.
type Proxy ¶
type Proxy interface { Name(complex128) string Args(complex128) (args int, bind Array.Any) Call(complex128, ...variant.Any) variant.Any Bind(complex128, ...variant.Any) (Proxy, complex128) }
Proxy can be implemented to provide a foreign-managed array representation. This can be useful when you want to access a callable with its implementation hosted in another programming language.