Callable

package
v0.0.0-...-ae8aae0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package Callable provides generic methods for working with callable functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgumentCount

func ArgumentCount(fn Function) int

ArgumentCount returns the total number of arguments this Callable should take.

func BoundArguments

func BoundArguments(fn Function) Array.Any

BoundArguments returns the arguments that have been bound to this Callable.

func BoundArgumentsCount

func BoundArgumentsCount(fn Function) int

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 Cycle

func Cycle()

Cycle calls all functions in the defer queue.

func Defer

func Defer(fn Function, args ...variant.Any)

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

func Hash(fn Function) uint32

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 IsNil

func IsNil(fn Function) bool

IsNil returns true if the given value is nil.

func IsProxy

func IsProxy(fn Function) bool

IsProxy returns true if the given value is not backed by a Go function.

func IsStandard

func IsStandard(fn Function) bool

IsStandard returns true if the given value is backed by a Go function.

func IsValid

func IsValid(fn Function) bool

IsValid returns true if the given value is not nil.

func Method

func Method(fn Function) string

Method returns the name of the function represented by this Callable or an empty string if a name is not available.

func Receiver

func Receiver(fn Function) any

Receiver returns the receiver of the method represented by this Callable. If no receiver is available, this function returns nil.

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

func Bind(fn Function, args ...variant.Any) Function

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 Create

func Create(value any, method string) Function

Create creates a new Callable for the method named method in the specified value.

func New

func New(value any) Function

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

func Unbind(fn Function, argcount int) Function

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.

func (Function) Call

func (fn Function) Call(args ...variant.Any) variant.Any

Call calls the method represented by this Callable. Arguments can be passed and should match the method's signature.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL