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 ¶
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
Inspect returns a string-representation of the given object.
func (*Array) Next ¶ added in v2.1.11
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.
type Boolean ¶
type Boolean struct { // Value holds the boolean value we wrap. Value bool }
Boolean wraps bool and implements the Object interface.
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.
type ByName ¶ added in v2.1.14
type ByName []HashPair
ByName implements sort.Interface for []HashPair based on the Key field.
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) 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) 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.
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
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
Inspect returns a string-representation of the given object.
func (*Hash) Next ¶ added in v2.1.14
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.
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) 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) 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.
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) 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.
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
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.
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) Next ¶ added in v2.1.11
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.
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
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.