object

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 21 Imported by: 16

Documentation

Overview

Package object provides the standard set of Risor object types.

For external users of Risor, often an object.Object interface will be type asserted to a specific object type, such as *object.Float.

For example:

switch obj := obj.(type) {
case *object.String:
	// do something with obj.Value()
case *object.Float:
	// do something with obj.Value()
}

The Type() method of each object may also be used to get a string name of the object type, such as "string" or "float".

Index

Constants

This section is empty.

Variables

View Source
var (
	Nil   = &NilType{}
	True  = &Bool{value: true}
	False = &Bool{value: false}
)

Functions

func AsIterator added in v0.10.0

func AsIterator(obj Object) (Iterator, *Error)

func AsList

func AsList(obj Object) (*List, *Error)

func AsMap

func AsMap(obj Object) (*Map, *Error)

func AsObjects added in v0.14.0

func AsObjects(m map[string]any) (map[string]Object, error)

AsObjects transform a map containing arbitrary Go types to a map of Risor objects, using the best type converter for each type. If an item in the map is of a type that can't be converted, an error is returned.

func AsSet

func AsSet(obj Object) (*Set, *Error)

func CompareTypes

func CompareTypes(a, b Object) int

func Equals

func Equals(a, b Object) bool

func IsError

func IsError(obj Object) bool

func IsProxyableType

func IsProxyableType(typ reflect.Type) bool

func Keys added in v0.14.0

func Keys(m map[string]Object) []string

Keys returns the keys of an object map as a sorted slice of strings.

func NewArgumentsError

func NewArgumentsError(message string, args ...interface{}) error

func ResolveIndex

func ResolveIndex(idx int64, size int64) (int64, error)

ResolveIndex checks that the index is inbounds and transforms a negative index into the corresponding positive index. If the index is out of bounds, an error is returned.

func ResolveIntSlice

func ResolveIntSlice(slice Slice, size int64) (start int64, stop int64, err error)

ResolveIntSlice checks that the slice start and stop indices are inbounds and transforms negative indices into the corresponding positive indices. If the slice is out of bounds, an error is returned.

func SetTypeConverter

func SetTypeConverter(typ reflect.Type, conv TypeConverter)

SetTypeConverter sets a TypeConverter for the given Go type. This is not typically used, since the default converters should typically be sufficient.

func WithCallFunc

func WithCallFunc(ctx context.Context, fn CallFunc) context.Context

WithCallFunc adds an CallFunc to the context, which can be used by objects to call a Risor function at runtime.

func WithCloneCallFunc added in v1.4.0

func WithCloneCallFunc(ctx context.Context, fn CallFunc) context.Context

WithCloneCallFunc returns a context with a "clone-call" function associated. This function can be used to clone a Risor VM and then call a function on it synchronously.

func WithSpawnFunc added in v1.4.0

func WithSpawnFunc(ctx context.Context, fn SpawnFunc) context.Context

WithSpawnFunc adds an SpawnFunc to the context, which can be used by objects to spawn themselves.

Types

type ArgumentsError

type ArgumentsError struct {
	// contains filtered or unexported fields
}

func (*ArgumentsError) Error

func (e *ArgumentsError) Error() string

type ArrayConverter

type ArrayConverter struct {
	// contains filtered or unexported fields
}

ArrayConverter converts between []T and the Risor equivalent of []T.

func (*ArrayConverter) From

func (c *ArrayConverter) From(iface interface{}) (Object, error)

func (*ArrayConverter) To

func (c *ArrayConverter) To(obj Object) (interface{}, error)

type AttrResolver added in v0.10.0

type AttrResolver interface {
	ResolveAttr(ctx context.Context, name string) (Object, error)
}

AttrResolver is an interface used to resolve dynamic attributes on an object.

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool wraps bool and implements Object and Hashable interface.

func NewBool

func NewBool(value bool) *Bool

func Not

func Not(b *Bool) *Bool

func (*Bool) Compare

func (b *Bool) Compare(other Object) (int, error)

func (Bool) Cost

func (b Bool) Cost() int

func (*Bool) Equals

func (b *Bool) Equals(other Object) Object

func (Bool) GetAttr

func (b Bool) GetAttr(name string) (Object, bool)

func (*Bool) HashKey

func (b *Bool) HashKey() HashKey

func (*Bool) Inspect

func (b *Bool) Inspect() string

func (*Bool) Interface

func (b *Bool) Interface() interface{}

func (*Bool) IsTruthy

func (b *Bool) IsTruthy() bool

func (*Bool) MarshalJSON

func (b *Bool) MarshalJSON() ([]byte, error)

func (*Bool) RunOperation

func (b *Bool) RunOperation(opType op.BinaryOpType, right Object) Object

func (Bool) SetAttr

func (b Bool) SetAttr(name string, value Object) error

func (*Bool) String

func (b *Bool) String() string

func (*Bool) Type

func (b *Bool) Type() Type

func (*Bool) Value

func (b *Bool) Value() bool

type BoolConverter

type BoolConverter struct{}

BoolConverter converts between bool and *Bool.

func (*BoolConverter) From

func (c *BoolConverter) From(obj interface{}) (Object, error)

func (*BoolConverter) To

func (c *BoolConverter) To(obj Object) (interface{}, error)

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(buf *bytes.Buffer) *Buffer

func NewBufferFromBytes

func NewBufferFromBytes(value []byte) *Buffer

func (*Buffer) Compare

func (b *Buffer) Compare(other Object) (int, error)

func (*Buffer) Cost

func (b *Buffer) Cost() int

func (*Buffer) Equals

func (b *Buffer) Equals(other Object) Object

func (*Buffer) GetAttr

func (b *Buffer) GetAttr(name string) (Object, bool)

func (*Buffer) Inspect

func (b *Buffer) Inspect() string

func (*Buffer) Interface

func (b *Buffer) Interface() interface{}

func (*Buffer) IsTruthy

func (b *Buffer) IsTruthy() bool

func (*Buffer) MarshalJSON

func (b *Buffer) MarshalJSON() ([]byte, error)

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (n int, err error)

func (*Buffer) RunOperation

func (b *Buffer) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Buffer) SetAttr

func (b *Buffer) SetAttr(name string, value Object) error

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Type

func (b *Buffer) Type() Type

func (*Buffer) Value

func (b *Buffer) Value() *bytes.Buffer

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

type BufferConverter

type BufferConverter struct{}

BufferConverter converts between *bytes.Buffer and *Buffer.

func (*BufferConverter) From

func (c *BufferConverter) From(obj interface{}) (Object, error)

func (*BufferConverter) To

func (c *BufferConverter) To(obj Object) (interface{}, error)

type Builtin

type Builtin struct {
	// contains filtered or unexported fields
}

Builtin wraps func and implements Object interface.

func NewBuiltin

func NewBuiltin(name string, fn BuiltinFunction, module ...*Module) *Builtin

func NewErrorHandler

func NewErrorHandler(name string, fn BuiltinFunction, module ...*Module) *Builtin

func NewNoopBuiltin

func NewNoopBuiltin(name string, module *Module) *Builtin

NewNoopBuiltin creates a builtin function that has no effect.

func (*Builtin) Call

func (b *Builtin) Call(ctx context.Context, args ...Object) Object

func (Builtin) Cost

func (b Builtin) Cost() int

func (*Builtin) Equals

func (b *Builtin) Equals(other Object) Object

func (*Builtin) GetAttr

func (b *Builtin) GetAttr(name string) (Object, bool)

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Interface

func (b *Builtin) Interface() interface{}

func (*Builtin) IsErrorHandler

func (b *Builtin) IsErrorHandler() bool

func (Builtin) IsTruthy

func (b Builtin) IsTruthy() bool

func (*Builtin) Key

func (b *Builtin) Key() string

Returns a string that uniquely identifies this builtin function.

func (*Builtin) MarshalJSON

func (b *Builtin) MarshalJSON() ([]byte, error)

func (*Builtin) Name

func (b *Builtin) Name() string

func (*Builtin) RunOperation

func (b *Builtin) RunOperation(opType op.BinaryOpType, right Object) Object

func (Builtin) SetAttr

func (b Builtin) SetAttr(name string, value Object) error

func (*Builtin) String

func (b *Builtin) String() string

func (*Builtin) Type

func (b *Builtin) Type() Type

func (*Builtin) Value

func (b *Builtin) Value() BuiltinFunction

type BuiltinFunction

type BuiltinFunction func(ctx context.Context, args ...Object) Object

BuiltinFunction holds the type of a built-in function.

type Byte

type Byte struct {
	// contains filtered or unexported fields
}

Byte wraps byte and implements Object and Hashable interface.

func NewByte

func NewByte(value byte) *Byte

func (*Byte) Compare

func (b *Byte) Compare(other Object) (int, error)

func (Byte) Cost

func (b Byte) Cost() int

func (*Byte) Equals

func (b *Byte) Equals(other Object) Object

func (Byte) GetAttr

func (b Byte) GetAttr(name string) (Object, bool)

func (*Byte) HashKey

func (b *Byte) HashKey() HashKey

func (*Byte) Inspect

func (b *Byte) Inspect() string

func (*Byte) Interface

func (b *Byte) Interface() interface{}

func (*Byte) IsTruthy

func (b *Byte) IsTruthy() bool

func (*Byte) MarshalJSON

func (b *Byte) MarshalJSON() ([]byte, error)

func (*Byte) RunOperation

func (b *Byte) RunOperation(opType op.BinaryOpType, right Object) Object

func (Byte) SetAttr

func (b Byte) SetAttr(name string, value Object) error

func (*Byte) String

func (b *Byte) String() string

func (*Byte) Type

func (b *Byte) Type() Type

func (*Byte) Value

func (b *Byte) Value() byte

type ByteConverter

type ByteConverter struct{}

ByteConverter converts between byte and *Byte.

func (*ByteConverter) From

func (c *ByteConverter) From(obj interface{}) (Object, error)

func (*ByteConverter) To

func (c *ByteConverter) To(obj Object) (interface{}, error)

type ByteSlice

type ByteSlice struct {
	// contains filtered or unexported fields
}

func NewByteSlice

func NewByteSlice(value []byte) *ByteSlice

func (*ByteSlice) Clone

func (b *ByteSlice) Clone() *ByteSlice

func (*ByteSlice) Compare

func (b *ByteSlice) Compare(other Object) (int, error)

func (*ByteSlice) Contains

func (b *ByteSlice) Contains(obj Object) *Bool

func (*ByteSlice) ContainsAny

func (b *ByteSlice) ContainsAny(obj Object) Object

func (*ByteSlice) ContainsRune

func (b *ByteSlice) ContainsRune(obj Object) Object

func (*ByteSlice) Cost

func (b *ByteSlice) Cost() int

func (*ByteSlice) Count

func (b *ByteSlice) Count(obj Object) Object

func (*ByteSlice) DelItem

func (b *ByteSlice) DelItem(key Object) *Error

func (*ByteSlice) Equals

func (b *ByteSlice) Equals(other Object) Object

func (*ByteSlice) GetAttr

func (b *ByteSlice) GetAttr(name string) (Object, bool)

func (*ByteSlice) GetItem

func (b *ByteSlice) GetItem(key Object) (Object, *Error)

func (*ByteSlice) GetSlice

func (b *ByteSlice) GetSlice(slice Slice) (Object, *Error)

func (*ByteSlice) HasPrefix

func (b *ByteSlice) HasPrefix(obj Object) Object

func (*ByteSlice) HasSuffix

func (b *ByteSlice) HasSuffix(obj Object) Object

func (*ByteSlice) HashKey

func (b *ByteSlice) HashKey() HashKey

func (*ByteSlice) Index

func (b *ByteSlice) Index(obj Object) Object

func (*ByteSlice) IndexAny

func (b *ByteSlice) IndexAny(obj Object) Object

func (*ByteSlice) IndexByte

func (b *ByteSlice) IndexByte(obj Object) Object

func (*ByteSlice) IndexRune

func (b *ByteSlice) IndexRune(obj Object) Object

func (*ByteSlice) Inspect

func (b *ByteSlice) Inspect() string

func (*ByteSlice) Integers

func (b *ByteSlice) Integers() []Object

func (*ByteSlice) Interface

func (b *ByteSlice) Interface() interface{}

func (*ByteSlice) IsTruthy

func (b *ByteSlice) IsTruthy() bool

func (*ByteSlice) Iter

func (b *ByteSlice) Iter() Iterator

func (*ByteSlice) Len

func (b *ByteSlice) Len() *Int

func (*ByteSlice) MarshalJSON

func (b *ByteSlice) MarshalJSON() ([]byte, error)

func (*ByteSlice) Repeat

func (b *ByteSlice) Repeat(obj Object) Object

func (*ByteSlice) Replace

func (b *ByteSlice) Replace(old, new, count Object) Object

func (*ByteSlice) ReplaceAll

func (b *ByteSlice) ReplaceAll(old, new Object) Object

func (*ByteSlice) Reversed

func (b *ByteSlice) Reversed() *ByteSlice

func (*ByteSlice) RunOperation

func (b *ByteSlice) RunOperation(opType op.BinaryOpType, right Object) Object

func (ByteSlice) SetAttr

func (b ByteSlice) SetAttr(name string, value Object) error

func (*ByteSlice) SetItem

func (b *ByteSlice) SetItem(key, value Object) *Error

func (*ByteSlice) String

func (b *ByteSlice) String() string

func (*ByteSlice) Type

func (b *ByteSlice) Type() Type

func (*ByteSlice) Value

func (b *ByteSlice) Value() []byte

type ByteSliceConverter

type ByteSliceConverter struct{}

ByteSliceConverter converts between []byte and *ByteSlice.

func (*ByteSliceConverter) From

func (c *ByteSliceConverter) From(obj interface{}) (Object, error)

func (*ByteSliceConverter) To

func (c *ByteSliceConverter) To(obj Object) (interface{}, error)

type CallFunc

type CallFunc func(ctx context.Context, fn *Function, args []Object) (Object, error)

CallFunc is a type signature for a function that can call a Risor function.

func GetCallFunc

func GetCallFunc(ctx context.Context) (CallFunc, bool)

GetCallFunc returns the CallFunc from the context, if it exists.

func GetCloneCallFunc added in v1.4.0

func GetCloneCallFunc(ctx context.Context) (CallFunc, bool)

GetCloneCallFunc returns the "clone-call" function from the context, if it exists. This function can be used to clone a Risor VM and then call a function on it synchronously.

type Callable added in v0.17.0

type Callable interface {
	// Call invokes the callable with the given arguments and returns the result.
	Call(ctx context.Context, args ...Object) Object
}

Callable is an interface that exposes a Call method.

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

func NewCell

func NewCell(value *Object) *Cell

func (Cell) Cost

func (b Cell) Cost() int

func (*Cell) Equals

func (c *Cell) Equals(other Object) Object

func (Cell) GetAttr

func (b Cell) GetAttr(name string) (Object, bool)

func (*Cell) Inspect

func (c *Cell) Inspect() string

func (*Cell) Interface

func (c *Cell) Interface() interface{}

func (Cell) IsTruthy

func (b Cell) IsTruthy() bool

func (*Cell) MarshalJSON

func (c *Cell) MarshalJSON() ([]byte, error)

func (*Cell) RunOperation

func (c *Cell) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Cell) Set

func (c *Cell) Set(value Object)

func (Cell) SetAttr

func (b Cell) SetAttr(name string, value Object) error

func (*Cell) String

func (c *Cell) String() string

func (*Cell) Type

func (c *Cell) Type() Type

func (*Cell) Value

func (c *Cell) Value() Object

type Chan added in v1.4.0

type Chan struct {
	// contains filtered or unexported fields
}

func NewChan added in v1.4.0

func NewChan(size int) *Chan

func (*Chan) Capacity added in v1.4.0

func (c *Chan) Capacity() int

func (*Chan) Close added in v1.4.0

func (c *Chan) Close() (err error)

func (*Chan) Cost added in v1.4.0

func (c *Chan) Cost() int

func (*Chan) Entry added in v1.4.0

func (c *Chan) Entry() (IteratorEntry, bool)

func (*Chan) Equals added in v1.4.0

func (c *Chan) Equals(other Object) Object

func (*Chan) GetAttr added in v1.4.0

func (c *Chan) GetAttr(name string) (Object, bool)

func (*Chan) Inspect added in v1.4.0

func (c *Chan) Inspect() string

func (*Chan) Interface added in v1.4.0

func (c *Chan) Interface() interface{}

func (*Chan) IsTruthy added in v1.4.0

func (c *Chan) IsTruthy() bool

func (*Chan) Iter added in v1.4.0

func (c *Chan) Iter() Iterator

func (*Chan) MarshalJSON added in v1.4.0

func (c *Chan) MarshalJSON() ([]byte, error)

func (*Chan) Next added in v1.4.0

func (c *Chan) Next(ctx context.Context) (Object, bool)

func (*Chan) Receive added in v1.4.0

func (c *Chan) Receive(ctx context.Context) (Object, error)

func (*Chan) RunOperation added in v1.4.0

func (c *Chan) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Chan) Send added in v1.4.0

func (c *Chan) Send(ctx context.Context, value Object) (err error)

func (*Chan) SetAttr added in v1.4.0

func (c *Chan) SetAttr(name string, value Object) error

func (*Chan) Type added in v1.4.0

func (c *Chan) Type() Type

func (*Chan) Value added in v1.4.0

func (c *Chan) Value() chan Object

type Color

type Color struct {
	// contains filtered or unexported fields
}

func NewColor

func NewColor(c color.Color) *Color

func (Color) Cost

func (b Color) Cost() int

func (*Color) Equals

func (c *Color) Equals(other Object) Object

func (*Color) GetAttr

func (c *Color) GetAttr(name string) (Object, bool)

func (*Color) Inspect

func (c *Color) Inspect() string

func (*Color) Interface

func (c *Color) Interface() interface{}

func (Color) IsTruthy

func (b Color) IsTruthy() bool

func (*Color) MarshalJSON

func (c *Color) MarshalJSON() ([]byte, error)

func (*Color) RunOperation

func (c *Color) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Color) SetAttr

func (c *Color) SetAttr(name string, value Object) error

func (*Color) String

func (c *Color) String() string

func (*Color) Type

func (c *Color) Type() Type

func (*Color) Value

func (c *Color) Value() color.Color

type Comparable

type Comparable interface {
	Compare(other Object) (int, error)
}

Comparable is an interface used to compare two objects.

-1 if this < other
 0 if this == other
 1 if this > other

type Container

type Container interface {
	Iterable

	// GetItem implements the [key] operator for a container type.
	GetItem(key Object) (Object, *Error)

	// GetSlice implements the [start:stop] operator for a container type.
	GetSlice(s Slice) (Object, *Error)

	// SetItem implements the [key] = value operator for a container type.
	SetItem(key, value Object) *Error

	// DelItem implements the del [key] operator for a container type.
	DelItem(key Object) *Error

	// Contains returns true if the given item is found in this container.
	Contains(item Object) *Bool

	// Len returns the number of items in this container.
	Len() *Int
}

type ContextConverter

type ContextConverter struct{}

ContextConverter converts between context.Context and Context.

func (*ContextConverter) From

func (c *ContextConverter) From(obj interface{}) (Object, error)

func (*ContextConverter) To

func (c *ContextConverter) To(obj Object) (interface{}, error)

type DirEntry

type DirEntry struct {
	// contains filtered or unexported fields
}

func NewDirEntry

func NewDirEntry(value ros.DirEntry, fileInfo ...*FileInfo) *DirEntry

func (*DirEntry) Cost

func (d *DirEntry) Cost() int

func (*DirEntry) Equals

func (d *DirEntry) Equals(other Object) Object

func (*DirEntry) FileInfo

func (d *DirEntry) FileInfo() (*FileInfo, bool)

func (*DirEntry) GetAttr

func (d *DirEntry) GetAttr(name string) (Object, bool)

func (*DirEntry) Inspect

func (d *DirEntry) Inspect() string

func (*DirEntry) Interface

func (d *DirEntry) Interface() interface{}

func (*DirEntry) IsTruthy

func (d *DirEntry) IsTruthy() bool

func (*DirEntry) MarshalJSON

func (d *DirEntry) MarshalJSON() ([]byte, error)

func (*DirEntry) RunOperation

func (d *DirEntry) RunOperation(opType op.BinaryOpType, right Object) Object

func (*DirEntry) SetAttr

func (d *DirEntry) SetAttr(name string, value Object) error

func (*DirEntry) String

func (d *DirEntry) String() string

func (*DirEntry) Type

func (d *DirEntry) Type() Type

func (*DirEntry) Value

func (d *DirEntry) Value() ros.DirEntry

type DynamicAttr added in v0.10.0

type DynamicAttr struct {
	// contains filtered or unexported fields
}

DynamicAttr is an Object that represents an attribute that can be dynamically resolved to a concrete Object at runtime.

func NewDynamicAttr added in v0.10.0

func NewDynamicAttr(name string, fn ResolveAttrFunc) *DynamicAttr

func (*DynamicAttr) Cost added in v0.10.0

func (d *DynamicAttr) Cost() int

func (*DynamicAttr) Equals added in v0.10.0

func (d *DynamicAttr) Equals(other Object) Object

func (*DynamicAttr) GetAttr added in v0.10.0

func (d *DynamicAttr) GetAttr(name string) (Object, bool)

func (*DynamicAttr) Inspect added in v0.10.0

func (d *DynamicAttr) Inspect() string

func (*DynamicAttr) Interface added in v0.10.0

func (d *DynamicAttr) Interface() interface{}

func (*DynamicAttr) IsTruthy added in v0.10.0

func (d *DynamicAttr) IsTruthy() bool

func (*DynamicAttr) MarshalJSON added in v0.10.0

func (d *DynamicAttr) MarshalJSON() ([]byte, error)

func (*DynamicAttr) ResolveAttr added in v0.10.0

func (d *DynamicAttr) ResolveAttr(ctx context.Context, name string) (Object, error)

func (*DynamicAttr) RunOperation added in v0.10.0

func (d *DynamicAttr) RunOperation(opType op.BinaryOpType, right Object) Object

func (*DynamicAttr) SetAttr added in v0.10.0

func (d *DynamicAttr) SetAttr(name string, value Object) error

func (*DynamicAttr) String added in v0.10.0

func (d *DynamicAttr) String() string

func (*DynamicAttr) Type added in v0.10.0

func (d *DynamicAttr) Type() Type

type DynamicConverter

type DynamicConverter struct{}

DynamicConverter converts between interface{} and the appropriate Risor type. This is slow and should only be used to handle unknown types.

func (*DynamicConverter) From

func (c *DynamicConverter) From(obj interface{}) (Object, error)

func (*DynamicConverter) To

func (c *DynamicConverter) To(obj Object) (interface{}, error)

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

func NewEntry

func NewEntry(key, value Object) *Entry

func (Entry) Cost

func (b Entry) Cost() int

func (*Entry) Equals

func (e *Entry) Equals(other Object) Object

func (*Entry) GetAttr

func (e *Entry) GetAttr(name string) (Object, bool)

func (*Entry) Inspect

func (e *Entry) Inspect() string

func (*Entry) Interface

func (e *Entry) Interface() interface{}

func (Entry) IsTruthy

func (b Entry) IsTruthy() bool

func (*Entry) Key

func (e *Entry) Key() Object

func (*Entry) MarshalJSON

func (e *Entry) MarshalJSON() ([]byte, error)

func (*Entry) Primary

func (e *Entry) Primary() Object

func (*Entry) RunOperation

func (e *Entry) RunOperation(opType op.BinaryOpType, right Object) Object

func (Entry) SetAttr

func (b Entry) SetAttr(name string, value Object) error

func (*Entry) Type

func (e *Entry) Type() Type

func (*Entry) Value

func (e *Entry) Value() Object

func (*Entry) WithKeyAsPrimary

func (e *Entry) WithKeyAsPrimary() *Entry

func (*Entry) WithValueAsPrimary

func (e *Entry) WithValueAsPrimary() *Entry

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error wraps a Go error interface and implements Object.

func AsBool

func AsBool(obj Object) (bool, *Error)

func AsByte

func AsByte(obj Object) (byte, *Error)

func AsBytes

func AsBytes(obj Object) ([]byte, *Error)

func AsFloat

func AsFloat(obj Object) (float64, *Error)

func AsInt

func AsInt(obj Object) (int64, *Error)

func AsReader

func AsReader(obj Object) (io.Reader, *Error)

func AsString

func AsString(obj Object) (string, *Error)

func AsStringSlice added in v1.1.0

func AsStringSlice(obj Object) ([]string, *Error)

func AsTime

func AsTime(obj Object) (result time.Time, err *Error)

func AsWriter added in v0.17.0

func AsWriter(obj Object) (io.Writer, *Error)

func Errorf

func Errorf(format string, a ...interface{}) *Error

func NewArgsError

func NewArgsError(fn string, takes, given int) *Error

func NewArgsRangeError

func NewArgsRangeError(fn string, takesMin, takesMax, given int) *Error

func NewError

func NewError(err error) *Error

func Sort

func Sort(items []Object) *Error

Sort a list in place. If the list contains a non-comparable object, an error is returned.

func (*Error) Compare

func (e *Error) Compare(other Object) (int, error)

func (Error) Cost

func (b Error) Cost() int

func (*Error) Equals

func (e *Error) Equals(other Object) Object

func (Error) GetAttr

func (b Error) GetAttr(name string) (Object, bool)

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Interface

func (e *Error) Interface() interface{}

func (Error) IsTruthy

func (b Error) IsTruthy() bool

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

func (*Error) Message

func (e *Error) Message() *String

func (*Error) RunOperation

func (e *Error) RunOperation(opType op.BinaryOpType, right Object) Object

func (Error) SetAttr

func (b Error) SetAttr(name string, value Object) error

func (*Error) String

func (e *Error) String() string

func (*Error) Type

func (e *Error) Type() Type

func (*Error) Value

func (e *Error) Value() error

type ErrorConverter

type ErrorConverter struct{}

ErrorConverter converts between error and *Error or *String.

func (*ErrorConverter) From

func (c *ErrorConverter) From(obj interface{}) (Object, error)

func (*ErrorConverter) To

func (c *ErrorConverter) To(obj Object) (interface{}, error)

type File

type File struct {
	// contains filtered or unexported fields
}

func NewFile

func NewFile(ctx context.Context, value ros.File, path string) *File

func (*File) Close

func (f *File) Close() error

func (*File) Cost

func (f *File) Cost() int

func (*File) Equals

func (f *File) Equals(other Object) Object

func (*File) GetAttr

func (f *File) GetAttr(name string) (Object, bool)

func (*File) Inspect

func (f *File) Inspect() string

func (*File) Interface

func (f *File) Interface() interface{}

func (File) IsTruthy

func (b File) IsTruthy() bool

func (*File) Iter added in v0.10.0

func (f *File) Iter() Iterator

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

func (*File) Position

func (f *File) Position() (int64, error)

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

func (*File) RunOperation

func (f *File) RunOperation(opType op.BinaryOpType, right Object) Object

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (File) SetAttr

func (b File) SetAttr(name string, value Object) error

func (*File) String

func (f *File) String() string

func (*File) Type

func (f *File) Type() Type

func (*File) Value

func (f *File) Value() ros.File

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

type FileInfo

type FileInfo struct {
	// contains filtered or unexported fields
}

func NewFileInfo

func NewFileInfo(value ros.FileInfo) *FileInfo

func (*FileInfo) Cost

func (f *FileInfo) Cost() int

func (*FileInfo) Equals

func (f *FileInfo) Equals(other Object) Object

func (*FileInfo) GetAttr

func (f *FileInfo) GetAttr(name string) (Object, bool)

func (*FileInfo) Inspect

func (f *FileInfo) Inspect() string

func (*FileInfo) Interface

func (f *FileInfo) Interface() interface{}

func (*FileInfo) IsTruthy

func (f *FileInfo) IsTruthy() bool

func (*FileInfo) MarshalJSON

func (f *FileInfo) MarshalJSON() ([]byte, error)

func (*FileInfo) RunOperation

func (f *FileInfo) RunOperation(opType op.BinaryOpType, right Object) Object

func (*FileInfo) SetAttr

func (f *FileInfo) SetAttr(name string, value Object) error

func (*FileInfo) String

func (f *FileInfo) String() string

func (*FileInfo) Type

func (f *FileInfo) Type() Type

func (*FileInfo) Value

func (f *FileInfo) Value() ros.FileInfo

type FileIter added in v0.10.0

type FileIter struct {
	// contains filtered or unexported fields
}

func NewFileIter added in v0.10.0

func NewFileIter(f *File) *FileIter

func (FileIter) Cost added in v0.10.0

func (b FileIter) Cost() int

func (*FileIter) Entry added in v0.10.0

func (iter *FileIter) Entry() (IteratorEntry, bool)

func (*FileIter) Equals added in v0.10.0

func (iter *FileIter) Equals(other Object) Object

func (*FileIter) GetAttr added in v0.10.0

func (iter *FileIter) GetAttr(name string) (Object, bool)

func (*FileIter) Inspect added in v0.10.0

func (iter *FileIter) Inspect() string

func (*FileIter) Interface added in v0.10.0

func (iter *FileIter) Interface() interface{}

func (*FileIter) IsTruthy added in v0.10.0

func (iter *FileIter) IsTruthy() bool

func (*FileIter) MarshalJSON added in v0.10.0

func (iter *FileIter) MarshalJSON() ([]byte, error)

func (*FileIter) Next added in v0.10.0

func (iter *FileIter) Next(ctx context.Context) (Object, bool)

func (*FileIter) RunOperation added in v0.10.0

func (iter *FileIter) RunOperation(opType op.BinaryOpType, right Object) Object

func (FileIter) SetAttr added in v0.10.0

func (b FileIter) SetAttr(name string, value Object) error

func (*FileIter) String added in v0.10.0

func (iter *FileIter) String() string

func (*FileIter) Type added in v0.10.0

func (iter *FileIter) Type() Type

type FileMode

type FileMode struct {
	// contains filtered or unexported fields
}

func NewFileMode

func NewFileMode(value ros.FileMode) *FileMode

func (*FileMode) Compare

func (m *FileMode) Compare(other Object) (int, error)

func (*FileMode) Cost

func (m *FileMode) Cost() int

func (*FileMode) Equals

func (m *FileMode) Equals(other Object) Object

func (*FileMode) GetAttr

func (m *FileMode) GetAttr(name string) (Object, bool)

func (*FileMode) Inspect

func (m *FileMode) Inspect() string

func (*FileMode) Interface

func (m *FileMode) Interface() interface{}

func (*FileMode) IsTruthy

func (m *FileMode) IsTruthy() bool

func (*FileMode) MarshalJSON

func (m *FileMode) MarshalJSON() ([]byte, error)

func (*FileMode) RunOperation

func (m *FileMode) RunOperation(opType op.BinaryOpType, right Object) Object

func (*FileMode) SetAttr

func (m *FileMode) SetAttr(name string, value Object) error

func (*FileMode) String

func (m *FileMode) String() string

func (*FileMode) Type

func (m *FileMode) Type() Type

func (*FileMode) Value

func (m *FileMode) Value() ros.FileMode

type Float

type Float struct {
	// contains filtered or unexported fields
}

Float wraps float64 and implements Object and Hashable interfaces.

func NewFloat

func NewFloat(value float64) *Float

func (*Float) Compare

func (f *Float) Compare(other Object) (int, error)

func (Float) Cost

func (b Float) Cost() int

func (*Float) Equals

func (f *Float) Equals(other Object) Object

func (Float) GetAttr

func (b Float) GetAttr(name string) (Object, bool)

func (*Float) HashKey

func (f *Float) HashKey() HashKey

func (*Float) Inspect

func (f *Float) Inspect() string

func (*Float) Interface

func (f *Float) Interface() interface{}

func (*Float) IsTruthy

func (f *Float) IsTruthy() bool

func (*Float) MarshalJSON

func (f *Float) MarshalJSON() ([]byte, error)

func (*Float) RunOperation

func (f *Float) RunOperation(opType op.BinaryOpType, right Object) Object

func (Float) SetAttr

func (b Float) SetAttr(name string, value Object) error

func (*Float) String

func (f *Float) String() string

func (*Float) Type

func (f *Float) Type() Type

func (*Float) Value

func (f *Float) Value() float64

type Float32Converter

type Float32Converter struct{}

Float32Converter converts between float32 and *Float.

func (*Float32Converter) From

func (c *Float32Converter) From(obj interface{}) (Object, error)

func (*Float32Converter) To

func (c *Float32Converter) To(obj Object) (interface{}, error)

type Float64Converter

type Float64Converter struct{}

Float64Converter converts between float64 and *Float.

func (*Float64Converter) From

func (c *Float64Converter) From(obj interface{}) (Object, error)

func (*Float64Converter) To

func (c *Float64Converter) To(obj Object) (interface{}, error)

type FloatSlice

type FloatSlice struct {
	// contains filtered or unexported fields
}

func NewFloatSlice

func NewFloatSlice(value []float64) *FloatSlice

func (*FloatSlice) Clone

func (f *FloatSlice) Clone() *FloatSlice

func (*FloatSlice) Contains

func (f *FloatSlice) Contains(item Object) *Bool

func (*FloatSlice) Cost

func (f *FloatSlice) Cost() int

func (*FloatSlice) DelItem

func (f *FloatSlice) DelItem(key Object) *Error

func (*FloatSlice) Equals

func (f *FloatSlice) Equals(other Object) Object

func (*FloatSlice) GetAttr

func (f *FloatSlice) GetAttr(name string) (Object, bool)

func (*FloatSlice) GetItem

func (f *FloatSlice) GetItem(key Object) (Object, *Error)

func (*FloatSlice) GetSlice

func (f *FloatSlice) GetSlice(slice Slice) (Object, *Error)

func (*FloatSlice) Inspect

func (f *FloatSlice) Inspect() string

func (*FloatSlice) Integers

func (f *FloatSlice) Integers() []Object

func (*FloatSlice) Interface

func (f *FloatSlice) Interface() interface{}

func (*FloatSlice) IsTruthy

func (f *FloatSlice) IsTruthy() bool

func (*FloatSlice) Iter

func (f *FloatSlice) Iter() Iterator

func (*FloatSlice) Len

func (f *FloatSlice) Len() *Int

func (*FloatSlice) MarshalJSON

func (f *FloatSlice) MarshalJSON() ([]byte, error)

func (*FloatSlice) RunOperation

func (f *FloatSlice) RunOperation(opType op.BinaryOpType, right Object) Object

func (FloatSlice) SetAttr

func (b FloatSlice) SetAttr(name string, value Object) error

func (*FloatSlice) SetItem

func (f *FloatSlice) SetItem(key, value Object) *Error

func (*FloatSlice) String

func (f *FloatSlice) String() string

func (*FloatSlice) Type

func (f *FloatSlice) Type() Type

func (*FloatSlice) Value

func (f *FloatSlice) Value() []float64

type FloatSliceConverter

type FloatSliceConverter struct{}

FloatSliceConverter converts between []float64 and *FloatSlice.

func (*FloatSliceConverter) From

func (c *FloatSliceConverter) From(obj interface{}) (Object, error)

func (*FloatSliceConverter) To

func (c *FloatSliceConverter) To(obj Object) (interface{}, error)

type Function

type Function struct {
	// contains filtered or unexported fields
}

Function is a function that has been compiled to bytecode.

func NewClosure

func NewClosure(
	fn *Function,
	freeVars []*Cell,
) *Function

func NewFunction

func NewFunction(fn *compiler.Function) *Function

func (*Function) Call added in v1.4.0

func (f *Function) Call(ctx context.Context, args ...Object) Object

func (*Function) Code

func (f *Function) Code() *compiler.Code

func (Function) Cost

func (b Function) Cost() int

func (*Function) Defaults

func (f *Function) Defaults() []Object

func (*Function) Equals

func (f *Function) Equals(other Object) Object

func (*Function) FreeVars

func (f *Function) FreeVars() []*Cell

func (*Function) Function added in v0.14.0

func (f *Function) Function() *compiler.Function

func (*Function) GetAttr

func (f *Function) GetAttr(name string) (Object, bool)

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Instructions

func (f *Function) Instructions() []op.Code

func (*Function) Interface

func (f *Function) Interface() interface{}

func (Function) IsTruthy

func (b Function) IsTruthy() bool

func (*Function) LocalsCount

func (f *Function) LocalsCount() int

func (*Function) MarshalJSON

func (f *Function) MarshalJSON() ([]byte, error)

func (*Function) Name

func (f *Function) Name() string

func (*Function) Parameters

func (f *Function) Parameters() []string

func (*Function) RequiredArgsCount

func (f *Function) RequiredArgsCount() int

func (*Function) RunOperation

func (f *Function) RunOperation(opType op.BinaryOpType, right Object) Object

func (Function) SetAttr

func (b Function) SetAttr(name string, value Object) error

func (*Function) String

func (f *Function) String() string

func (*Function) Type

func (f *Function) Type() Type

type FunctionOpts

type FunctionOpts struct {
	Name           string
	ParameterNames []string
	Defaults       []Object
	Code           *compiler.Code
}

type GoAttribute

type GoAttribute interface {
	// Name of the attribute.
	Name() string
}

GoAttribute is an interface to represent an attribute on a Go type. This could be either a field or a method.

type GoField

type GoField struct {
	// contains filtered or unexported fields
}

GoField represents a single field on a Go type that can be read or written.

func (*GoField) Converter

func (f *GoField) Converter() (TypeConverter, bool)

func (GoField) Cost

func (b GoField) Cost() int

func (*GoField) Equals

func (f *GoField) Equals(other Object) Object

func (*GoField) GetAttr

func (f *GoField) GetAttr(name string) (Object, bool)

func (*GoField) GoType

func (f *GoField) GoType() *GoType

func (*GoField) Inspect

func (f *GoField) Inspect() string

func (*GoField) Interface

func (f *GoField) Interface() interface{}

func (*GoField) IsTruthy

func (f *GoField) IsTruthy() bool

func (*GoField) MarshalJSON

func (f *GoField) MarshalJSON() ([]byte, error)

func (*GoField) Name

func (f *GoField) Name() string

func (*GoField) ReflectType

func (f *GoField) ReflectType() reflect.Type

func (*GoField) RunOperation

func (f *GoField) RunOperation(opType op.BinaryOpType, right Object) Object

func (GoField) SetAttr

func (b GoField) SetAttr(name string, value Object) error

func (*GoField) Tag

func (f *GoField) Tag() reflect.StructTag

func (*GoField) Type

func (f *GoField) Type() Type

type GoMethod

type GoMethod struct {
	// contains filtered or unexported fields
}

GoMethod represents a single method on a Go type. This exposes the method to Risor for reflection and proxying.

func (GoMethod) Cost

func (b GoMethod) Cost() int

func (*GoMethod) Equals

func (m *GoMethod) Equals(other Object) Object

func (*GoMethod) ErrorIndices

func (m *GoMethod) ErrorIndices() []int

func (*GoMethod) GetAttr

func (m *GoMethod) GetAttr(name string) (Object, bool)

func (*GoMethod) HasPointerReceiver added in v0.13.0

func (m *GoMethod) HasPointerReceiver() bool

func (*GoMethod) InType

func (m *GoMethod) InType(i int) *GoType

func (*GoMethod) Inspect

func (m *GoMethod) Inspect() string

func (*GoMethod) Interface

func (m *GoMethod) Interface() interface{}

func (*GoMethod) IsOutputError

func (m *GoMethod) IsOutputError(index int) bool

func (*GoMethod) IsTruthy

func (m *GoMethod) IsTruthy() bool

func (*GoMethod) MarshalJSON

func (m *GoMethod) MarshalJSON() ([]byte, error)

func (*GoMethod) Name

func (m *GoMethod) Name() string

func (*GoMethod) NumIn

func (m *GoMethod) NumIn() int

func (*GoMethod) NumOut

func (m *GoMethod) NumOut() int

func (*GoMethod) OutType

func (m *GoMethod) OutType(i int) *GoType

func (*GoMethod) ProducesError

func (m *GoMethod) ProducesError() bool

func (*GoMethod) RunOperation

func (m *GoMethod) RunOperation(opType op.BinaryOpType, right Object) Object

func (GoMethod) SetAttr

func (b GoMethod) SetAttr(name string, value Object) error

func (*GoMethod) Type

func (m *GoMethod) Type() Type

type GoType

type GoType struct {
	// contains filtered or unexported fields
}

GoType wraps a single native Go type to make it easier to work with in Risor and also to be able to represent the type as a Risor object.

func NewGoType

func NewGoType(typ reflect.Type) (*GoType, error)

NewGoType registers and returns a Risor GoType for the type of the given native Go object. This is safe for concurrent use by multiple goroutines. A type registry is maintained behind the scenes to ensure that each type is only registered once.

func (*GoType) AttributeNames

func (t *GoType) AttributeNames() []string

func (GoType) Cost

func (b GoType) Cost() int

func (*GoType) Equals

func (t *GoType) Equals(other Object) Object

func (*GoType) GetAttr

func (t *GoType) GetAttr(name string) (Object, bool)

func (*GoType) GetAttribute

func (t *GoType) GetAttribute(name string) (GoAttribute, bool)

func (*GoType) GetConverter added in v0.13.0

func (t *GoType) GetConverter() (TypeConverter, error)

func (*GoType) HasDirectMethod added in v0.13.0

func (t *GoType) HasDirectMethod(name string) bool

func (*GoType) IndirectType

func (t *GoType) IndirectType() *GoType

func (*GoType) Inspect

func (t *GoType) Inspect() string

func (*GoType) Interface

func (t *GoType) Interface() interface{}

func (*GoType) IsPointerType added in v0.13.0

func (t *GoType) IsPointerType() bool

func (*GoType) IsTruthy

func (t *GoType) IsTruthy() bool

func (*GoType) MarshalJSON

func (t *GoType) MarshalJSON() ([]byte, error)

func (*GoType) Name

func (t *GoType) Name() string

func (*GoType) New added in v0.13.0

func (t *GoType) New() reflect.Value

func (*GoType) PackagePath

func (t *GoType) PackagePath() string

func (*GoType) PointerType added in v0.13.0

func (t *GoType) PointerType() *GoType

func (*GoType) ReflectType

func (t *GoType) ReflectType() reflect.Type

func (*GoType) RunOperation

func (t *GoType) RunOperation(opType op.BinaryOpType, right Object) Object

func (GoType) SetAttr

func (b GoType) SetAttr(name string, value Object) error

func (*GoType) Type

func (t *GoType) Type() Type

func (*GoType) ValueType added in v0.13.0

func (t *GoType) ValueType() *GoType

type HashKey

type HashKey struct {
	// Type of the object being referenced.
	Type Type
	// FltValue is used as the key for floats.
	FltValue float64
	// IntValue is used as the key for integers.
	IntValue int64
	// StrValue is used as the key for strings.
	StrValue string
}

HashKey is used to identify unique values in a set.

type Hashable

type Hashable interface {
	// Hash returns a hash key for the given object.
	HashKey() HashKey
}

Hashable types can be hashed and consequently used in a set.

type Int

type Int struct {
	// contains filtered or unexported fields
}

Int wraps int64 and implements Object and Hashable interfaces.

func NewInt

func NewInt(value int64) *Int

func (*Int) Compare

func (i *Int) Compare(other Object) (int, error)

func (Int) Cost

func (b Int) Cost() int

func (*Int) Equals

func (i *Int) Equals(other Object) Object

func (Int) GetAttr

func (b Int) GetAttr(name string) (Object, bool)

func (*Int) HashKey

func (i *Int) HashKey() HashKey

func (*Int) Inspect

func (i *Int) Inspect() string

func (*Int) Interface

func (i *Int) Interface() interface{}

func (*Int) IsTruthy

func (i *Int) IsTruthy() bool

func (*Int) Iter added in v1.4.0

func (i *Int) Iter() Iterator

func (*Int) MarshalJSON

func (i *Int) MarshalJSON() ([]byte, error)

func (*Int) RunOperation

func (i *Int) RunOperation(opType op.BinaryOpType, right Object) Object

func (Int) SetAttr

func (b Int) SetAttr(name string, value Object) error

func (*Int) String

func (i *Int) String() string

func (*Int) Type

func (i *Int) Type() Type

func (*Int) Value

func (i *Int) Value() int64

type Int16Converter

type Int16Converter struct{}

Int16Converter converts between int16 and *Int.

func (*Int16Converter) From

func (c *Int16Converter) From(obj interface{}) (Object, error)

func (*Int16Converter) To

func (c *Int16Converter) To(obj Object) (interface{}, error)

type Int32Converter

type Int32Converter struct{}

Int32Converter converts between int32 and *Int.

func (*Int32Converter) From

func (c *Int32Converter) From(obj interface{}) (Object, error)

func (*Int32Converter) To

func (c *Int32Converter) To(obj Object) (interface{}, error)

type Int64Converter

type Int64Converter struct{}

Int64Converter converts between int64 and *Int.

func (*Int64Converter) From

func (c *Int64Converter) From(obj interface{}) (Object, error)

func (*Int64Converter) To

func (c *Int64Converter) To(obj Object) (interface{}, error)

type Int8Converter

type Int8Converter struct{}

Int8Converter converts between int8 and *Int.

func (*Int8Converter) From

func (c *Int8Converter) From(obj interface{}) (Object, error)

func (*Int8Converter) To

func (c *Int8Converter) To(obj Object) (interface{}, error)

type IntConverter

type IntConverter struct{}

IntConverter converts between int and *Int.

func (*IntConverter) From

func (c *IntConverter) From(obj interface{}) (Object, error)

func (*IntConverter) To

func (c *IntConverter) To(obj Object) (interface{}, error)

type IntIter added in v1.4.0

type IntIter struct {
	// contains filtered or unexported fields
}

func NewIntIter added in v1.4.0

func NewIntIter(i *Int) *IntIter

func (IntIter) Cost added in v1.4.0

func (b IntIter) Cost() int

func (*IntIter) Entry added in v1.4.0

func (iter *IntIter) Entry() (IteratorEntry, bool)

func (*IntIter) Equals added in v1.4.0

func (iter *IntIter) Equals(other Object) Object

func (*IntIter) GetAttr added in v1.4.0

func (iter *IntIter) GetAttr(name string) (Object, bool)

func (*IntIter) Inspect added in v1.4.0

func (iter *IntIter) Inspect() string

func (*IntIter) Interface added in v1.4.0

func (iter *IntIter) Interface() interface{}

func (*IntIter) IsTruthy added in v1.4.0

func (iter *IntIter) IsTruthy() bool

func (*IntIter) MarshalJSON added in v1.4.0

func (iter *IntIter) MarshalJSON() ([]byte, error)

func (*IntIter) Next added in v1.4.0

func (iter *IntIter) Next(ctx context.Context) (Object, bool)

func (*IntIter) RunOperation added in v1.4.0

func (iter *IntIter) RunOperation(opType op.BinaryOpType, right Object) Object

func (IntIter) SetAttr added in v1.4.0

func (b IntIter) SetAttr(name string, value Object) error

func (*IntIter) String added in v1.4.0

func (iter *IntIter) String() string

func (*IntIter) Type added in v1.4.0

func (iter *IntIter) Type() Type

type Iterable added in v0.10.0

type Iterable interface {
	Iter() Iterator
}

Iterable is an interface that exposes an iterator for an Object.

type Iterator

type Iterator interface {
	Object

	// Next advances the iterator and then returns the current object and a
	// bool indicating whether the returned item is valid. Once Next() has been
	// called, the Entry() method can be used to get an IteratorEntry.
	Next(context.Context) (Object, bool)

	// Entry returns the current entry in the iterator and a bool indicating
	// whether the returned item is valid.
	Entry() (IteratorEntry, bool)
}

Iterator is an interface used to iterate over a container.

type IteratorEntry

type IteratorEntry interface {
	Object
	Key() Object
	Value() Object
	Primary() Object
}

IteratorEntry is a single item returned by an iterator.

type List

type List struct {
	// contains filtered or unexported fields
}

List of objects

func NewList

func NewList(items []Object) *List

func NewStringList

func NewStringList(s []string) *List

func (*List) Append

func (ls *List) Append(obj Object)

Append adds an item at the end of the list.

func (*List) Clear

func (ls *List) Clear()

Clear removes all the items from the list.

func (*List) Compare

func (ls *List) Compare(other Object) (int, error)

func (*List) Contains

func (ls *List) Contains(item Object) *Bool

Contains returns true if the given item is found in this container.

func (*List) Copy

func (ls *List) Copy() *List

Copy returns a shallow copy of the list.

func (*List) Cost

func (ls *List) Cost() int

func (*List) Count

func (ls *List) Count(obj Object) int64

Count returns the number of items with the specified value.

func (*List) DelItem

func (ls *List) DelItem(key Object) *Error

DelItem implements the del [key] operator for a container type.

func (*List) Each

func (ls *List) Each(ctx context.Context, fn Object) Object

func (*List) Equals

func (ls *List) Equals(other Object) Object

func (*List) Extend

func (ls *List) Extend(other *List)

Extend adds the items of a list to the end of the current list.

func (*List) Filter

func (ls *List) Filter(ctx context.Context, fn Object) Object

func (*List) GetAttr

func (ls *List) GetAttr(name string) (Object, bool)

func (*List) GetItem

func (ls *List) GetItem(key Object) (Object, *Error)

func (*List) GetSlice

func (ls *List) GetSlice(s Slice) (Object, *Error)

GetSlice implements the [start:stop] operator for a container type.

func (*List) Index

func (ls *List) Index(obj Object) int64

Index returns the index of the first item with the specified value.

func (*List) Insert

func (ls *List) Insert(index int64, obj Object)

Insert adds an item at the specified position.

func (*List) Inspect

func (ls *List) Inspect() string

func (*List) Interface

func (ls *List) Interface() interface{}

func (*List) IsTruthy

func (ls *List) IsTruthy() bool

func (*List) Iter

func (ls *List) Iter() Iterator

func (*List) Keys

func (ls *List) Keys() Object

func (*List) Len

func (ls *List) Len() *Int

Len returns the number of items in this container.

func (*List) Map

func (ls *List) Map(ctx context.Context, fn Object) Object

func (*List) MarshalJSON

func (ls *List) MarshalJSON() ([]byte, error)

func (*List) Pop

func (ls *List) Pop(index int64) Object

Pop removes the item at the specified position.

func (*List) Remove

func (ls *List) Remove(obj Object)

Remove removes the first item with the specified value.

func (*List) Reverse

func (ls *List) Reverse()

Reverse reverses the order of the list.

func (*List) Reversed

func (ls *List) Reversed() *List

func (*List) RunOperation

func (ls *List) RunOperation(opType op.BinaryOpType, right Object) Object

func (List) SetAttr

func (b List) SetAttr(name string, value Object) error

func (*List) SetItem

func (ls *List) SetItem(key, value Object) *Error

SetItem implements the [key] = value operator for a container type.

func (*List) Size

func (ls *List) Size() int

func (*List) String

func (ls *List) String() string

func (*List) Type

func (ls *List) Type() Type

func (*List) Value

func (ls *List) Value() []Object

type ListIter

type ListIter struct {
	// contains filtered or unexported fields
}

func NewListIter

func NewListIter(l *List) *ListIter

func (ListIter) Cost

func (b ListIter) Cost() int

func (*ListIter) Entry

func (iter *ListIter) Entry() (IteratorEntry, bool)

func (*ListIter) Equals

func (iter *ListIter) Equals(other Object) Object

func (*ListIter) GetAttr

func (iter *ListIter) GetAttr(name string) (Object, bool)

func (*ListIter) Inspect

func (iter *ListIter) Inspect() string

func (*ListIter) Interface

func (iter *ListIter) Interface() interface{}

func (*ListIter) IsTruthy

func (iter *ListIter) IsTruthy() bool

func (*ListIter) MarshalJSON

func (iter *ListIter) MarshalJSON() ([]byte, error)

func (*ListIter) Next

func (iter *ListIter) Next(ctx context.Context) (Object, bool)

func (*ListIter) RunOperation

func (iter *ListIter) RunOperation(opType op.BinaryOpType, right Object) Object

func (ListIter) SetAttr

func (b ListIter) SetAttr(name string, value Object) error

func (*ListIter) String

func (iter *ListIter) String() string

func (*ListIter) Type

func (iter *ListIter) Type() Type

type Map

type Map struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap(m map[string]Object) *Map

func (*Map) Clear

func (m *Map) Clear()

func (*Map) Contains

func (m *Map) Contains(key Object) *Bool

Contains returns true if the given item is found in this container.

func (*Map) Copy

func (m *Map) Copy() *Map

func (*Map) Cost

func (m *Map) Cost() int

func (*Map) DelItem

func (m *Map) DelItem(key Object) *Error

DelItem deletes the item with the given key from the map.

func (*Map) Delete

func (m *Map) Delete(key string) Object

func (*Map) Equals

func (m *Map) Equals(other Object) Object

func (*Map) Get

func (m *Map) Get(key string) Object

func (*Map) GetAttr

func (m *Map) GetAttr(name string) (Object, bool)

func (*Map) GetItem

func (m *Map) GetItem(key Object) (Object, *Error)

func (*Map) GetSlice

func (m *Map) GetSlice(s Slice) (Object, *Error)

GetSlice implements the [start:stop] operator for a container type.

func (*Map) GetWithDefault

func (m *Map) GetWithDefault(key string, defaultValue Object) Object

func (*Map) GetWithObject

func (m *Map) GetWithObject(key *String) Object

func (*Map) Inspect

func (m *Map) Inspect() string

func (*Map) Interface

func (m *Map) Interface() interface{}

func (*Map) IsTruthy

func (m *Map) IsTruthy() bool

func (*Map) Iter

func (m *Map) Iter() Iterator

func (*Map) Keys

func (m *Map) Keys() *List

func (*Map) Len

func (m *Map) Len() *Int

Len returns the number of items in this container.

func (*Map) ListItems

func (m *Map) ListItems() *List

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

func (*Map) Pop

func (m *Map) Pop(key string, def Object) Object

func (*Map) RunOperation

func (m *Map) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Map) Set

func (m *Map) Set(key string, value Object)

func (*Map) SetAttr

func (m *Map) SetAttr(name string, value Object) error

func (*Map) SetDefault

func (m *Map) SetDefault(key string, value Object) Object

func (*Map) SetItem

func (m *Map) SetItem(key, value Object) *Error

SetItem assigns a value to the given key in the map.

func (*Map) Size

func (m *Map) Size() int

func (*Map) SortedKeys

func (m *Map) SortedKeys() []string

func (*Map) String

func (m *Map) String() string

func (*Map) StringKeys

func (m *Map) StringKeys() []string

func (*Map) Type

func (m *Map) Type() Type

func (*Map) Update

func (m *Map) Update(other *Map)

func (*Map) Value

func (m *Map) Value() map[string]Object

func (*Map) Values

func (m *Map) Values() *List

type MapConverter

type MapConverter struct {
	// contains filtered or unexported fields
}

MapConverter converts between map[string]interface{} and *Map.

func (*MapConverter) From

func (c *MapConverter) From(obj interface{}) (Object, error)

func (*MapConverter) To

func (c *MapConverter) To(obj Object) (interface{}, error)

type MapIter

type MapIter struct {
	// contains filtered or unexported fields
}

func NewMapIter

func NewMapIter(m *Map) *MapIter

func (MapIter) Cost

func (b MapIter) Cost() int

func (*MapIter) Entry

func (iter *MapIter) Entry() (IteratorEntry, bool)

func (*MapIter) Equals

func (iter *MapIter) Equals(other Object) Object

func (*MapIter) GetAttr

func (iter *MapIter) GetAttr(name string) (Object, bool)

func (*MapIter) Inspect

func (iter *MapIter) Inspect() string

func (*MapIter) Interface

func (iter *MapIter) Interface() interface{}

func (*MapIter) IsTruthy

func (iter *MapIter) IsTruthy() bool

func (*MapIter) MarshalJSON

func (iter *MapIter) MarshalJSON() ([]byte, error)

func (*MapIter) Next

func (iter *MapIter) Next(ctx context.Context) (Object, bool)

func (*MapIter) RunOperation

func (iter *MapIter) RunOperation(opType op.BinaryOpType, right Object) Object

func (MapIter) SetAttr

func (b MapIter) SetAttr(name string, value Object) error

func (*MapIter) String

func (iter *MapIter) String() string

func (*MapIter) Type

func (iter *MapIter) Type() Type

type Module

type Module struct {
	// contains filtered or unexported fields
}

func NewBuiltinsModule

func NewBuiltinsModule(name string, contents map[string]Object, callableOption ...BuiltinFunction) *Module

func NewModule

func NewModule(name string, code *compiler.Code) *Module

func (*Module) Call added in v0.17.0

func (m *Module) Call(ctx context.Context, args ...Object) Object

func (*Module) Code

func (m *Module) Code() *compiler.Code

func (*Module) Compare

func (m *Module) Compare(other Object) (int, error)

func (Module) Cost

func (b Module) Cost() int

func (*Module) Equals

func (m *Module) Equals(other Object) Object

func (*Module) GetAttr

func (m *Module) GetAttr(name string) (Object, bool)

func (*Module) Inspect

func (m *Module) Inspect() string

func (*Module) Interface

func (m *Module) Interface() interface{}

func (Module) IsTruthy

func (b Module) IsTruthy() bool

func (*Module) MarshalJSON

func (m *Module) MarshalJSON() ([]byte, error)

func (*Module) Name

func (m *Module) Name() *String

func (*Module) Override added in v1.3.0

func (m *Module) Override(name string, value Object) error

Override provides a mechanism to modify module attributes after loading. Whether or not this is exposed to Risor scripts changes the security posture of reusing modules. By default, this is not exposed to scripting. Overriding with a value of nil is equivalent to deleting the attribute.

func (*Module) RunOperation

func (m *Module) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Module) SetAttr

func (m *Module) SetAttr(name string, value Object) error

func (*Module) String

func (m *Module) String() string

func (*Module) Type

func (m *Module) Type() Type

func (*Module) UseGlobals added in v0.15.0

func (m *Module) UseGlobals(globals []Object)

type NilType

type NilType struct {
	// contains filtered or unexported fields
}

func (*NilType) Compare

func (n *NilType) Compare(other Object) (int, error)

func (NilType) Cost

func (b NilType) Cost() int

func (*NilType) Equals

func (n *NilType) Equals(other Object) Object

func (NilType) GetAttr

func (b NilType) GetAttr(name string) (Object, bool)

func (*NilType) HashKey

func (n *NilType) HashKey() HashKey

func (*NilType) Inspect

func (n *NilType) Inspect() string

func (*NilType) Interface

func (n *NilType) Interface() interface{}

func (*NilType) IsTruthy

func (n *NilType) IsTruthy() bool

func (*NilType) MarshalJSON

func (n *NilType) MarshalJSON() ([]byte, error)

func (*NilType) RunOperation

func (n *NilType) RunOperation(opType op.BinaryOpType, right Object) Object

func (NilType) SetAttr

func (b NilType) SetAttr(name string, value Object) error

func (*NilType) String

func (n *NilType) String() string

func (*NilType) Type

func (n *NilType) Type() Type

type Object

type Object interface {
	// Type of the object.
	Type() Type

	// Inspect returns a string representation of the given object.
	Inspect() string

	// Interface converts the given object to a native Go value.
	Interface() interface{}

	// Returns True if the given object is equal to this object.
	Equals(other Object) Object

	// GetAttr returns the attribute with the given name from this object.
	GetAttr(name string) (Object, bool)

	// SetAttr sets the attribute with the given name on this object.
	SetAttr(name string, value Object) error

	// IsTruthy returns true if the object is considered "truthy".
	IsTruthy() bool

	// RunOperation runs an operation on this object with the given
	// right-hand side object.
	RunOperation(opType op.BinaryOpType, right Object) Object

	// Cost returns the incremental processing cost of this object.
	Cost() int
}

Object is the interface that all object types in Risor must implement.

func BinaryOp

func BinaryOp(opType op.BinaryOpType, a, b Object) Object

BinaryOp performs a binary operation on two objects, given an operator.

func Compare

func Compare(opType op.CompareOpType, a, b Object) Object

Compare two objects using the given comparison operator. An Error object is returned if either of the objects is not comparable.

func FromGoType

func FromGoType(obj interface{}) Object

func NewSet

func NewSet(items []Object) Object

type Partial

type Partial struct {
	// contains filtered or unexported fields
}

Partial is a partially applied function

func NewPartial

func NewPartial(fn Object, args []Object) *Partial

func (*Partial) Args

func (p *Partial) Args() []Object

func (Partial) Cost

func (b Partial) Cost() int

func (*Partial) Equals

func (p *Partial) Equals(other Object) Object

func (*Partial) Function

func (p *Partial) Function() Object

func (Partial) GetAttr

func (b Partial) GetAttr(name string) (Object, bool)

func (*Partial) Inspect

func (p *Partial) Inspect() string

func (*Partial) Interface

func (p *Partial) Interface() interface{}

func (Partial) IsTruthy

func (b Partial) IsTruthy() bool

func (*Partial) MarshalJSON

func (p *Partial) MarshalJSON() ([]byte, error)

func (*Partial) RunOperation

func (p *Partial) RunOperation(opType op.BinaryOpType, right Object) Object

func (Partial) SetAttr

func (b Partial) SetAttr(name string, value Object) error

func (*Partial) Type

func (p *Partial) Type() Type

type PointerConverter

type PointerConverter struct {
	// contains filtered or unexported fields
}

PointerConverter converts between *T and the Risor equivalent of T.

func (*PointerConverter) From

func (c *PointerConverter) From(obj interface{}) (Object, error)

func (*PointerConverter) To

func (c *PointerConverter) To(obj Object) (interface{}, error)

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy is a Risor type that proxies method calls to a wrapped Go struct. Only the public methods of the Go type are proxied.

func NewProxy

func NewProxy(obj interface{}) (*Proxy, error)

NewProxy returns a new Risor proxy object that wraps the given Go object. This operation may fail if the Go type has attributes whose types cannot be converted to Risor types.

func (Proxy) Cost

func (b Proxy) Cost() int

func (*Proxy) Equals

func (p *Proxy) Equals(other Object) Object

func (*Proxy) GetAttr

func (p *Proxy) GetAttr(name string) (Object, bool)

func (*Proxy) GoType

func (p *Proxy) GoType() *GoType

func (*Proxy) Inspect

func (p *Proxy) Inspect() string

func (*Proxy) Interface

func (p *Proxy) Interface() interface{}

func (Proxy) IsTruthy

func (b Proxy) IsTruthy() bool

func (*Proxy) MarshalJSON

func (p *Proxy) MarshalJSON() ([]byte, error)

func (*Proxy) RunOperation

func (p *Proxy) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Proxy) SetAttr

func (p *Proxy) SetAttr(name string, value Object) error

func (*Proxy) String

func (p *Proxy) String() string

func (*Proxy) Type

func (p *Proxy) Type() Type

type ResolveAttrFunc added in v0.10.0

type ResolveAttrFunc func(ctx context.Context, name string) (Object, error)

type RuneConverter

type RuneConverter struct{}

RuneConverter converts between rune and *String.

func (*RuneConverter) From

func (c *RuneConverter) From(obj interface{}) (Object, error)

func (*RuneConverter) To

func (c *RuneConverter) To(obj Object) (interface{}, error)

type Set

type Set struct {
	// contains filtered or unexported fields
}

func NewSetWithSize

func NewSetWithSize(size int) *Set

func (*Set) Add

func (s *Set) Add(items ...Object) Object

func (*Set) Clear

func (s *Set) Clear()

func (*Set) Contains

func (s *Set) Contains(key Object) *Bool

Contains returns true if the given item is found in this container.

func (*Set) Cost

func (s *Set) Cost() int

func (*Set) DelItem

func (s *Set) DelItem(key Object) *Error

DelItem deletes the item with the given key from the map.

func (*Set) Difference

func (s *Set) Difference(other *Set) *Set

Difference returns a new set that is the difference of the two sets.

func (*Set) Equals

func (s *Set) Equals(other Object) Object

func (*Set) GetAttr

func (s *Set) GetAttr(name string) (Object, bool)

func (*Set) GetItem

func (s *Set) GetItem(key Object) (Object, *Error)

func (*Set) GetSlice

func (s *Set) GetSlice(slice Slice) (Object, *Error)

GetSlice implements the [start:stop] operator for a container type.

func (*Set) Inspect

func (s *Set) Inspect() string

func (*Set) Interface

func (s *Set) Interface() interface{}

func (*Set) Intersection

func (s *Set) Intersection(other *Set) *Set

Intersection returns a new set that is the intersection of the two sets.

func (*Set) IsTruthy

func (s *Set) IsTruthy() bool

func (*Set) Iter

func (s *Set) Iter() Iterator

func (*Set) Keys

func (s *Set) Keys() []HashKey

func (*Set) Len

func (s *Set) Len() *Int

Len returns the number of items in this container.

func (*Set) List

func (s *Set) List() *List

func (*Set) MarshalJSON

func (s *Set) MarshalJSON() ([]byte, error)

func (*Set) Remove

func (s *Set) Remove(items ...Object) Object

func (*Set) RunOperation

func (s *Set) RunOperation(opType op.BinaryOpType, right Object) Object

func (Set) SetAttr

func (b Set) SetAttr(name string, value Object) error

func (*Set) SetItem

func (s *Set) SetItem(key, value Object) *Error

SetItem assigns a value to the given key in the map.

func (*Set) Size

func (s *Set) Size() int

func (*Set) SortedItems

func (s *Set) SortedItems() []Object

func (*Set) String

func (s *Set) String() string

func (*Set) Type

func (s *Set) Type() Type

func (*Set) Union

func (s *Set) Union(other *Set) *Set

Union returns a new set that is the union of the two sets.

func (*Set) Value

func (s *Set) Value() map[HashKey]Object

type SetIter

type SetIter struct {
	// contains filtered or unexported fields
}

func NewSetIter

func NewSetIter(set *Set) *SetIter

func (SetIter) Cost

func (b SetIter) Cost() int

func (*SetIter) Entry

func (iter *SetIter) Entry() (IteratorEntry, bool)

func (*SetIter) Equals

func (iter *SetIter) Equals(other Object) Object

func (*SetIter) GetAttr

func (iter *SetIter) GetAttr(name string) (Object, bool)

func (*SetIter) Inspect

func (iter *SetIter) Inspect() string

func (*SetIter) Interface

func (iter *SetIter) Interface() interface{}

func (*SetIter) IsTruthy

func (iter *SetIter) IsTruthy() bool

func (*SetIter) MarshalJSON

func (iter *SetIter) MarshalJSON() ([]byte, error)

func (*SetIter) Next

func (iter *SetIter) Next(ctx context.Context) (Object, bool)

func (*SetIter) RunOperation

func (iter *SetIter) RunOperation(opType op.BinaryOpType, right Object) Object

func (SetIter) SetAttr

func (b SetIter) SetAttr(name string, value Object) error

func (*SetIter) String

func (iter *SetIter) String() string

func (*SetIter) Type

func (iter *SetIter) Type() Type

type Slice

type Slice struct {
	Start Object
	Stop  Object
}

Slice is used to specify a range or slice of items in a container.

type SliceConverter

type SliceConverter struct {
	// contains filtered or unexported fields
}

SliceConverter converts between []T and the Risor equivalent of []T.

func (*SliceConverter) From

func (c *SliceConverter) From(iface interface{}) (Object, error)

func (*SliceConverter) To

func (c *SliceConverter) To(obj Object) (interface{}, error)

type SliceIter

type SliceIter struct {
	// contains filtered or unexported fields
}

func NewSliceIter

func NewSliceIter(s interface{}) (*SliceIter, error)

func (SliceIter) Cost

func (b SliceIter) Cost() int

func (*SliceIter) Entry

func (iter *SliceIter) Entry() (IteratorEntry, bool)

func (*SliceIter) Equals

func (iter *SliceIter) Equals(other Object) Object

func (*SliceIter) GetAttr

func (iter *SliceIter) GetAttr(name string) (Object, bool)

func (*SliceIter) Inspect

func (iter *SliceIter) Inspect() string

func (*SliceIter) Interface

func (iter *SliceIter) Interface() interface{}

func (*SliceIter) IsTruthy

func (iter *SliceIter) IsTruthy() bool

func (*SliceIter) MarshalJSON

func (iter *SliceIter) MarshalJSON() ([]byte, error)

func (*SliceIter) Next

func (iter *SliceIter) Next(ctx context.Context) (Object, bool)

func (*SliceIter) RunOperation

func (iter *SliceIter) RunOperation(opType op.BinaryOpType, right Object) Object

func (SliceIter) SetAttr

func (b SliceIter) SetAttr(name string, value Object) error

func (*SliceIter) String

func (iter *SliceIter) String() string

func (*SliceIter) Type

func (iter *SliceIter) Type() Type

type SpawnFunc added in v1.4.0

type SpawnFunc func(ctx context.Context, fn Callable, args []Object) (*Thread, error)

SpawnFunc is a type signature for a function that can spawn a Risor thread.

func GetSpawnFunc added in v1.4.0

func GetSpawnFunc(ctx context.Context) (SpawnFunc, bool)

GetSpawnFunc returns the SpawnFunc from the context, if it exists.

type String

type String struct {
	// contains filtered or unexported fields
}

func NewString

func NewString(s string) *String

func (*String) Compare

func (s *String) Compare(other Object) (int, error)

func (*String) Contains

func (s *String) Contains(obj Object) *Bool

func (*String) Cost

func (s *String) Cost() int

func (*String) Count

func (s *String) Count(obj Object) Object

func (*String) DelItem

func (s *String) DelItem(key Object) *Error

func (*String) Equals

func (s *String) Equals(other Object) Object

func (*String) Fields

func (s *String) Fields() Object

func (*String) GetAttr

func (s *String) GetAttr(name string) (Object, bool)

func (*String) GetItem

func (s *String) GetItem(key Object) (Object, *Error)

func (*String) GetSlice

func (s *String) GetSlice(slice Slice) (Object, *Error)

func (*String) HasPrefix

func (s *String) HasPrefix(obj Object) Object

func (*String) HasSuffix

func (s *String) HasSuffix(obj Object) Object

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Index

func (s *String) Index(obj Object) Object

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Interface

func (s *String) Interface() interface{}

func (*String) IsTruthy

func (s *String) IsTruthy() bool

func (*String) Iter

func (s *String) Iter() Iterator

func (*String) Join

func (s *String) Join(obj Object) Object

func (*String) LastIndex

func (s *String) LastIndex(obj Object) Object

func (*String) Len

func (s *String) Len() *Int

func (*String) MarshalJSON

func (s *String) MarshalJSON() ([]byte, error)

func (*String) ReplaceAll

func (s *String) ReplaceAll(old, new Object) Object

func (*String) Reversed

func (s *String) Reversed() *String

func (*String) RunOperation

func (s *String) RunOperation(opType op.BinaryOpType, right Object) Object

func (*String) Runes

func (s *String) Runes() []Object

func (String) SetAttr

func (b String) SetAttr(name string, value Object) error

func (*String) SetItem

func (s *String) SetItem(key, value Object) *Error

func (*String) Split

func (s *String) Split(obj Object) Object

func (*String) String

func (s *String) String() string

func (*String) ToLower

func (s *String) ToLower() Object

func (*String) ToUpper

func (s *String) ToUpper() Object

func (*String) Trim

func (s *String) Trim(obj Object) Object

func (*String) TrimPrefix

func (s *String) TrimPrefix(obj Object) Object

func (*String) TrimSpace

func (s *String) TrimSpace() Object

func (*String) TrimSuffix

func (s *String) TrimSuffix(obj Object) Object

func (*String) Type

func (s *String) Type() Type

func (*String) Value

func (s *String) Value() string

type StringConverter

type StringConverter struct{}

StringConverter converts between string and *String.

func (*StringConverter) From

func (c *StringConverter) From(obj interface{}) (Object, error)

func (*StringConverter) To

func (c *StringConverter) To(obj Object) (interface{}, error)

type StructConverter

type StructConverter struct {
	// contains filtered or unexported fields
}

StructConverter converts between a Go struct and a Risor Proxy. Works with structs as values or pointers.

func (*StructConverter) From

func (c *StructConverter) From(obj interface{}) (Object, error)

func (*StructConverter) To

func (c *StructConverter) To(obj Object) (interface{}, error)

type Thread added in v1.4.0

type Thread struct {
	// contains filtered or unexported fields
}

func NewThread added in v1.4.0

func NewThread(ctx context.Context, callable Callable, args []Object) *Thread

func Spawn added in v1.4.0

func Spawn(ctx context.Context, fnObj Object, args []Object) (*Thread, error)

func (*Thread) Cost added in v1.4.0

func (t *Thread) Cost() int

func (*Thread) Equals added in v1.4.0

func (t *Thread) Equals(other Object) Object

func (*Thread) GetAttr added in v1.4.0

func (t *Thread) GetAttr(name string) (Object, bool)

func (*Thread) Inspect added in v1.4.0

func (t *Thread) Inspect() string

func (*Thread) Interface added in v1.4.0

func (t *Thread) Interface() interface{}

func (*Thread) IsTruthy added in v1.4.0

func (t *Thread) IsTruthy() bool

func (*Thread) MarshalJSON added in v1.4.0

func (t *Thread) MarshalJSON() ([]byte, error)

func (*Thread) RunOperation added in v1.4.0

func (t *Thread) RunOperation(opType op.BinaryOpType, right Object) Object

func (*Thread) SetAttr added in v1.4.0

func (t *Thread) SetAttr(name string, value Object) error

func (*Thread) Type added in v1.4.0

func (t *Thread) Type() Type

func (*Thread) Wait added in v1.4.0

func (t *Thread) Wait(ctx context.Context) Object

type Time

type Time struct {
	// contains filtered or unexported fields
}

func NewTime

func NewTime(t time.Time) *Time

func (*Time) After

func (t *Time) After(ctx context.Context, args ...Object) Object

func (*Time) Before

func (t *Time) Before(ctx context.Context, args ...Object) Object

func (*Time) Compare

func (t *Time) Compare(other Object) (int, error)

func (Time) Cost

func (b Time) Cost() int

func (*Time) Equals

func (t *Time) Equals(other Object) Object

func (*Time) Format

func (t *Time) Format(ctx context.Context, args ...Object) Object

func (*Time) GetAttr

func (t *Time) GetAttr(name string) (Object, bool)

func (*Time) Inspect

func (t *Time) Inspect() string

func (*Time) Interface

func (t *Time) Interface() interface{}

func (*Time) IsTruthy

func (t *Time) IsTruthy() bool

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

func (*Time) RunOperation

func (t *Time) RunOperation(opType op.BinaryOpType, right Object) Object

func (Time) SetAttr

func (b Time) SetAttr(name string, value Object) error

func (*Time) String

func (t *Time) String() string

func (*Time) Type

func (t *Time) Type() Type

func (*Time) UTC

func (t *Time) UTC(ctx context.Context, args ...Object) Object

func (*Time) Unix

func (t *Time) Unix(ctx context.Context, args ...Object) Object

func (*Time) Value

func (t *Time) Value() time.Time

type TimeConverter

type TimeConverter struct{}

TimeConverter converts between time.Time and *Time.

func (*TimeConverter) From

func (c *TimeConverter) From(obj interface{}) (Object, error)

func (*TimeConverter) To

func (c *TimeConverter) To(obj Object) (interface{}, error)

type Type

type Type string

Type of an object as a string.

const (
	BOOL          Type = "bool"
	BUFFER        Type = "buffer"
	BUILTIN       Type = "builtin"
	BYTE          Type = "byte"
	BYTE_SLICE    Type = "byte_slice"
	CELL          Type = "cell"
	CHANNEL       Type = "channel"
	COLOR         Type = "color"
	COMPLEX       Type = "complex"
	COMPLEX_SLICE Type = "complex_slice"
	DIR_ENTRY     Type = "dir_entry"
	DYNAMIC_ATTR  Type = "dynamic_attr"
	ERROR         Type = "error"
	FILE          Type = "file"
	FILE_INFO     Type = "file_info"
	FILE_ITER     Type = "file_iter"
	FILE_MODE     Type = "file_mode"
	FLOAT         Type = "float"
	FLOAT_SLICE   Type = "float_slice"
	FUNCTION      Type = "function"
	GO_FIELD      Type = "go_field"
	GO_METHOD     Type = "go_method"
	GO_TYPE       Type = "go_type"
	INT           Type = "int"
	INT_ITER      Type = "int_iter"
	ITER_ENTRY    Type = "iter_entry"
	LIST          Type = "list"
	LIST_ITER     Type = "list_iter"
	MAP           Type = "map"
	MAP_ITER      Type = "map_iter"
	MODULE        Type = "module"
	NIL           Type = "nil"
	PARTIAL       Type = "partial"
	PROXY         Type = "proxy"
	RESULT        Type = "result"
	SET           Type = "set"
	SET_ITER      Type = "set_iter"
	SLICE_ITER    Type = "slice_iter"
	STRING        Type = "string"
	STRING_ITER   Type = "string_iter"
	THREAD        Type = "thread"
	TIME          Type = "time"
)

Type constants

type TypeConverter

type TypeConverter interface {
	// To converts to a Go object from a Risor object.
	To(Object) (interface{}, error)

	// From converts a Go object to a Risor object.
	From(interface{}) (Object, error)
}

TypeConverter is an interface used to convert between Go and Risor objects for a single Go type.

func NewTypeConverter

func NewTypeConverter(typ reflect.Type) (TypeConverter, error)

NewTypeConverter returns a TypeConverter for the given Go kind and type. Converters are cached internally for reuse.

type Uint16Converter

type Uint16Converter struct{}

Uint16Converter converts between uint16 and *Int.

func (*Uint16Converter) From

func (c *Uint16Converter) From(obj interface{}) (Object, error)

func (*Uint16Converter) To

func (c *Uint16Converter) To(obj Object) (interface{}, error)

type Uint32Converter

type Uint32Converter struct{}

Uint32Converter converts between uint32 and *Int.

func (*Uint32Converter) From

func (c *Uint32Converter) From(obj interface{}) (Object, error)

func (*Uint32Converter) To

func (c *Uint32Converter) To(obj Object) (interface{}, error)

type Uint64Converter

type Uint64Converter struct{}

Uint64Converter converts between uint64 and *Int.

func (*Uint64Converter) From

func (c *Uint64Converter) From(obj interface{}) (Object, error)

func (*Uint64Converter) To

func (c *Uint64Converter) To(obj Object) (interface{}, error)

type Uint8Converter

type Uint8Converter struct{}

Uint8Converter converts between uint8 and *Int.

func (*Uint8Converter) From

func (c *Uint8Converter) From(obj interface{}) (Object, error)

func (*Uint8Converter) To

func (c *Uint8Converter) To(obj Object) (interface{}, error)

type UintConverter

type UintConverter struct{}

UintConverter converts between uint and *Int.

func (*UintConverter) From

func (c *UintConverter) From(obj interface{}) (Object, error)

func (*UintConverter) To

func (c *UintConverter) To(obj Object) (interface{}, error)

Jump to

Keyboard shortcuts

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