object

package
v2.1.19 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: GPL-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package object contains the golang-implementation of our evalfilter object-types.

Our scripting language supports several different object-types:

* Arrays. * Boolean values. * Floating-point numbers. * Hashes. * Integer numbers. * Null * String values. * Regular-expression objects.

To allow these objects to be used interchanagably each kind of object must implement the same simple interface.

There are additional interfaces for adding support for more advanced operations - such as iteration, incrementing, decrementing, and JSON export.

Index

Constants

View Source
const (
	ARRAY   = "ARRAY"
	BOOLEAN = "BOOLEAN"
	FLOAT   = "FLOAT"
	HASH    = "HASH"
	INTEGER = "INTEGER"
	NULL    = "NULL"
	REGEXP  = "REGEXP"
	STRING  = "STRING"
	VOID    = "VOID"
)

pre-defined object types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array added in v2.1.5

type Array struct {
	// Elements holds the individual members of the array we're wrapping.
	Elements []Object
	// contains filtered or unexported fields
}

Array wraps Object array and implements Object interface.

func (*Array) Inspect added in v2.1.5

func (ao *Array) Inspect() string

Inspect returns a string-representation of the given object.

func (*Array) JSON added in v2.1.18

func (ao *Array) JSON() (string, error)

JSON converts this object to a JSON string

func (*Array) Next added in v2.1.11

func (ao *Array) Next() (Object, Object, bool)

Next implements the Iterable interface, and allows the contents of our array to be iterated over.

func (*Array) Reset added in v2.1.11

func (ao *Array) Reset()

Reset implements the Iterable interface, and allows the contents of the array to be reset to allow re-iteration.

func (*Array) ToInterface added in v2.1.10

func (ao *Array) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Array) True added in v2.1.5

func (ao *Array) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Array) Type added in v2.1.5

func (ao *Array) Type() Type

Type returns the type of this object.

type Boolean

type Boolean struct {
	// Value holds the boolean value we wrap.
	Value bool
}

Boolean wraps bool and implements the Object interface.

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns a string-representation of the given object.

func (*Boolean) JSON added in v2.1.18

func (b *Boolean) JSON() (string, error)

JSON converts this object to a JSON string.

func (*Boolean) ToInterface added in v2.1.10

func (b *Boolean) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Boolean) True added in v2.1.4

func (b *Boolean) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type of this object.

type ByName added in v2.1.14

type ByName []HashPair

ByName implements sort.Interface for []HashPair based on the Key field.

func (ByName) Len added in v2.1.14

func (a ByName) Len() int

func (ByName) Less added in v2.1.14

func (a ByName) Less(i, j int) bool

func (ByName) Swap added in v2.1.14

func (a ByName) Swap(i, j int)

type Decrement added in v2.1.11

type Decrement interface {

	// Decrease lowers the object's value by one.
	Decrease()
}

Decrement is an interface that some objects might wish to support.

If this interface is implemented then it will be possible to use the the postfix `--` operator upon objects of that type, without that a run-time error will be generated.

type Float

type Float struct {
	// Value holds the float-value this object wraps.
	Value float64
}

Float wraps float64 and implements the Object interface.

func (*Float) Decrease added in v2.1.11

func (f *Float) Decrease()

Decrease implements the Decrement interface, and allows the postfix "--" operator to be applied to float-objects

func (*Float) HashKey added in v2.1.14

func (f *Float) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*Float) Increase added in v2.1.11

func (f *Float) Increase()

Increase implements the Increment interface, and allows the postfix "++" operator to be applied to float-objects

func (*Float) Inspect

func (f *Float) Inspect() string

Inspect returns a string-representation of the given object.

func (*Float) JSON added in v2.1.18

func (f *Float) JSON() (string, error)

JSON converts this object to a JSON string.

func (*Float) ToInterface added in v2.1.10

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

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Float) True added in v2.1.4

func (f *Float) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Float) Type

func (f *Float) Type() Type

Type returns the type of this object.

type Hash added in v2.1.14

type Hash struct {
	// Pairs holds the key/value pairs of the hash we wrap
	Pairs map[HashKey]HashPair
	// contains filtered or unexported fields
}

Hash wrap map[HashKey]HashPair and implements Object interface.

func (*Hash) Entries added in v2.1.14

func (h *Hash) Entries() []HashPair

Entries returns the sorted list of entries we maintain

We need this to guarantee a stable order when iterating, or exporting to a string.

func (*Hash) Inspect added in v2.1.14

func (h *Hash) Inspect() string

Inspect returns a string-representation of the given object.

func (*Hash) JSON added in v2.1.18

func (h *Hash) JSON() (string, error)

JSON converts this object to a JSON string.

func (*Hash) Next added in v2.1.14

func (h *Hash) Next() (Object, Object, bool)

Next implements the Iterable interface, and allows the contents of our array to be iterated over.

func (*Hash) Reset added in v2.1.14

func (h *Hash) Reset()

Reset implements the Iterable interface, and allows the contents of the array to be reset to allow re-iteration.

func (*Hash) ToInterface added in v2.1.14

func (h *Hash) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Hash) True added in v2.1.14

func (h *Hash) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Hash) Type added in v2.1.14

func (h *Hash) Type() Type

Type returns the type of this object.

type HashKey added in v2.1.14

type HashKey struct {
	// Type holds the type of the object.
	Type Type

	// Value holds the actual hash-key value.
	Value uint64
}

HashKey is the structure used for hash-keys

type HashPair added in v2.1.14

type HashPair struct {
	// Key holds our hash-key key.
	Key Object

	// Value holds our hash-key value.
	Value Object
}

HashPair is a structure which is used to store hash-entries

type Hashable added in v2.1.14

type Hashable interface {

	// HashKey returns a hash key for the given object.
	HashKey() HashKey
}

Hashable type can be hashed.

If an object-type implements this interface it can be used as the key in one of our hash-objects.

type Increment added in v2.1.11

type Increment interface {

	// Increase raises the object's value by one.
	Increase()
}

Increment is an interface that some objects might wish to support.

If this interface is implemented then it will be possible to use the the postfix `++` operator upon objects of that type, without that a run-time error will be generated.

type Integer

type Integer struct {
	// Value holds the integer value this object wraps
	Value int64
}

Integer wraps int64 and implements the Object interface.

func (*Integer) Decrease added in v2.1.11

func (i *Integer) Decrease()

Decrease implements the Decrement interface, and allows the postfix "--" operator to be applied to integer-objects

func (*Integer) HashKey added in v2.1.14

func (i *Integer) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*Integer) Increase added in v2.1.11

func (i *Integer) Increase()

Increase implements the Increment interface, and allows the postfix "++" operator to be applied to integer-objects

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns a string-representation of the given object.

func (*Integer) JSON added in v2.1.18

func (i *Integer) JSON() (string, error)

JSON converts this object to a JSON string.

func (*Integer) ToInterface added in v2.1.10

func (i *Integer) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Integer) True added in v2.1.4

func (i *Integer) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Integer) Type

func (i *Integer) Type() Type

Type returns the type of this object.

type Iterable added in v2.1.11

type Iterable interface {

	// Reset the state of any previous iteration.
	Reset()

	// Get the next "thing" from the object being iterated
	// over.
	//
	// The return values are the item which is to be returned
	// next, the index of that object, and finally a boolean
	// to say whether the function succeeded.
	//
	// If the boolean value returned is false then that
	// means the iteration has completed and no further
	// items are available.
	Next() (Object, Object, bool)
}

Iterable is an interface that some objects might wish to support.

If this interface is implemented then it will be possible to use the `foreach` function to iterate over the object. If the interface is not implemented then a run-time error will be generated instead.

type JSONAble added in v2.1.18

type JSONAble interface {

	// JSON will export this object to a JSON representation of
	// the contents of the object.
	JSON() (string, error)
}

JSONAble is an interface that some objects might wish to support.

If this interface is implemented then it will be possible to export the contents of a given object to JSON.

type Null

type Null struct{}

Null wraps nothing and implements our Object interface.

func (*Null) Inspect

func (n *Null) Inspect() string

Inspect returns a string-representation of the given object.

func (*Null) JSON added in v2.1.18

func (n *Null) JSON() (string, error)

JSON converts this object to a JSON string.

func (*Null) ToInterface added in v2.1.10

func (n *Null) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Null) True added in v2.1.4

func (n *Null) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Null) Type

func (n *Null) Type() Type

Type returns the type of this object.

type Object

type Object interface {

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

	// Type returns the type of this object.
	Type() Type

	// True returns whether this object is "true".
	//
	// This is used when an object is used in an `if` expression,
	// for example, or with the logical `&&` and `||` operations.
	True() bool

	// ToInterface converts the given object to a "native" golang value,
	// which is required to ensure that we can use the object in our
	// `sprintf` or `printf` primitives.
	ToInterface() interface{}
}

Object is the interface that all of our various object-types must implement.

This is a deliberately minimal interface, which should allow the easy addition of new types in the future.

type Regexp added in v2.1.14

type Regexp struct {
	// Value holds the string value this object wraps.
	//
	// (Yes we're a regexp, but we pretend we're string!)
	Value string
}

Regexp wraps string and implements the Object interface.

func (*Regexp) Inspect added in v2.1.14

func (r *Regexp) Inspect() string

Inspect returns a string-representation of the given object.

func (*Regexp) ToInterface added in v2.1.14

func (r *Regexp) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Regexp) True added in v2.1.14

func (r *Regexp) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Regexp) Type added in v2.1.14

func (r *Regexp) Type() Type

Type returns the type of this object.

type String

type String struct {
	// Value holds the string value this object wraps.
	Value string
	// contains filtered or unexported fields
}

String wraps string and implements the Object interface.

func (*String) HashKey added in v2.1.14

func (s *String) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns a string-representation of the given object.

func (*String) JSON added in v2.1.18

func (s *String) JSON() (string, error)

JSON converts this object to a JSON string.

func (*String) Next added in v2.1.11

func (s *String) Next() (Object, Object, bool)

Next implements the Iterable interface, and allows the contents of our string to be iterated over.

func (*String) Reset added in v2.1.11

func (s *String) Reset()

Reset implements the Iterable interface, and allows the contents of the string to be reset to allow re-iteration.

func (*String) ToInterface added in v2.1.10

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

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*String) True added in v2.1.4

func (s *String) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*String) Type

func (s *String) Type() Type

Type returns the type of this object.

type Type

type Type string

Type describes the type of an object.

type Void added in v2.1.11

type Void struct{}

Void wraps nothing and implements our Object interface.

If you're implementing a primitive in your host application, and the return value of that primitive doesn't matter, doesn't get used, and shouldn't be stored then this is the return-type you should use.

func (*Void) Inspect added in v2.1.11

func (v *Void) Inspect() string

Inspect returns a string-representation of the given object.

func (*Void) ToInterface added in v2.1.11

func (v *Void) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Void) True added in v2.1.11

func (v *Void) True() bool

True returns whether this object wraps a true-like value.

Used when this object is the conditional in a comparison, etc.

func (*Void) Type added in v2.1.11

func (v *Void) Type() Type

Type returns the type of this object.

Jump to

Keyboard shortcuts

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