Documentation ¶
Overview ¶
Package object contains our core-definitions for objects.
Index ¶
- Variables
- func IsError(obj ObjectI) bool
- type Array
- type Boolean
- type Builtin
- type BuiltinFunction
- type Environment
- type Error
- type File
- type Float
- type Function
- type Hash
- type HashKey
- type HashPair
- type HashableI
- type Integer
- type IterableI
- type Null
- type ObjectI
- type Regexp
- type ReturnValue
- type String
- func (s *String) HashKey() HashKey
- func (s *String) Inspect() string
- func (s *String) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
- func (s *String) Next() (ObjectI, ObjectI, bool)
- func (s *String) Reset()
- func (s *String) ToInterface() interface{}
- func (s *String) Type() objecttype.ObjectType
Constants ¶
This section is empty.
Variables ¶
var FALSE = &Boolean{Value: false}
var NULL = &Null{}
var TRUE = &Boolean{Value: true}
Functions ¶
Types ¶
type Array ¶
type Array struct { // Elements holds the individual members of the array we're wrapping. Elements []ObjectI // contains filtered or unexported fields }
Array wraps ObjectI array and implements ObjectI interface.
func (*Array) InvokeMethod ¶
func (ao *Array) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Array) Next ¶
Next implements the Iterable interface, and allows the contents of our array to be iterated over.
func (*Array) Reset ¶
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 ¶
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) Type ¶
func (ao *Array) Type() objecttype.ObjectType
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 ObjectI and Hashable interface.
func (*Boolean) InvokeMethod ¶
func (b *Boolean) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Boolean) ToInterface ¶
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) Type ¶
func (b *Boolean) Type() objecttype.ObjectType
Type returns the type of this object.
type Builtin ¶
type Builtin struct { // Value holds the function we wrap. Fn BuiltinFunction }
Builtin wraps func and implements ObjectI interface.
func (*Builtin) InvokeMethod ¶
func (b *Builtin) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Builtin) ToInterface ¶
func (b *Builtin) 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 (*Builtin) Type ¶
func (b *Builtin) Type() objecttype.ObjectType
Type returns the type of this object.
type BuiltinFunction ¶
type BuiltinFunction func(node asti.NodeI, env *Environment, args ...ObjectI) ObjectI
BuiltinFunction holds the type of a built-in function.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment stores our functions, variables, constants, etc.
func NewEnclosedEnvironment ¶
func NewEnclosedEnvironment(outer *Environment) *Environment
NewEnclosedEnvironment create new environment by outer parameter
func NewTemporaryScope ¶
func NewTemporaryScope(outer *Environment, keys []string) *Environment
NewTemporaryScope creates a temporary scope where some values are ignored.
This is used as a sneaky hack to allow `foreach` to access all global values as if they were local, but prevent the index/value keys from persisting.
func (*Environment) Get ¶
func (e *Environment) Get(name string) (ObjectI, bool)
Get returns the value of a given variable, by name.
func (*Environment) Names ¶
func (e *Environment) Names(prefix string) []string
Names returns the names of every known-value with the given prefix.
This function is used by `invokeMethod` to get the methods associated with a particular class-type.
func (*Environment) Set ¶
func (e *Environment) Set(name string, val ObjectI) ObjectI
Set stores the value of a variable, by name.
func (*Environment) SetConst ¶
func (e *Environment) SetConst(name string, val ObjectI) ObjectI
SetConst sets the value of a constant by name.
func (*Environment) String ¶
func (env *Environment) String() string
type Error ¶
type Error struct { // Message contains the error-message we're wrapping Message string Node asti.NodeI }
Error wraps string and implements ObjectI interface.
func (*Error) InvokeMethod ¶
func (e *Error) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Error) ToInterface ¶
func (e *Error) 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 (*Error) Type ¶
func (e *Error) Type() objecttype.ObjectType
Type returns the type of this object.
type File ¶
type File struct { // The path this file object refers to. Filename string // Reader is a helper for file-reading. Reader *bufio.Reader // Writer is a helper for file-writing. Writer *bufio.Writer // Handle contains the filehandle we wrap. Handle *os.File }
File wraps a file.
func (*File) InvokeMethod ¶
func (f *File) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*File) Open ¶
Open opens the file - called only from the open-primitive where the Filename will have been filled in for us.
func (*File) ToInterface ¶
func (f *File) 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 (*File) Type ¶
func (f *File) Type() objecttype.ObjectType
Type returns the type of this object.
type Float ¶
type Float struct { // Value holds the float-value this object wraps. Value float64 }
Float wraps float64 and implements ObjectI and Hashable interfaces.
func (*Float) InvokeMethod ¶
func (f *Float) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Float) ToInterface ¶
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) Type ¶
func (f *Float) Type() objecttype.ObjectType
Type returns the type of this object.
type Function ¶
type Function struct { Parameters []*ast.Identifier Body *ast.BlockStatement Defaults map[string]asti.ExpressionI Env *Environment }
Function wraps ast.Identifier array, ast.BlockStatement and Environment and implements ObjectI interface.
func (*Function) InvokeMethod ¶
func (f *Function) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Function) ToInterface ¶
func (f *Function) 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 (*Function) Type ¶
func (f *Function) Type() objecttype.ObjectType
Type returns the type of this object.
type Hash ¶
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 ObjectI interface.
func (*Hash) InvokeMethod ¶
func (h *Hash) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Hash) Next ¶
Next implements the Iterable interface, and allows the contents of our array to be iterated over.
func (*Hash) Reset ¶
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 ¶
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) Type ¶
func (h *Hash) Type() objecttype.ObjectType
Type returns the type of this object.
type HashKey ¶
type HashKey struct { // Type holds the type of the object. Type objecttype.ObjectType // Value holds the actual hash-key value. Value uint64 }
HashKey is the structure used for hash-keys
type HashPair ¶
type HashPair struct { // Key holds our hash-key key. Key ObjectI // Value holds our hash-key value. Value ObjectI }
HashPair is a structure which is used to store hash-entries
type HashableI ¶
type HashableI interface { // HashKey returns a hash key for the given object. HashKey() HashKey }
Hashable type can be hashed
type Integer ¶
type Integer struct { // Value holds the integer value this object wraps Value int64 }
Integer wraps int64 and implements ObjectI and Hashable interfaces.
func (*Integer) InvokeMethod ¶
func (i *Integer) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Integer) ToInterface ¶
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) Type ¶
func (i *Integer) Type() objecttype.ObjectType
Type returns the type of this object.
type IterableI ¶
type IterableI 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() (ObjectI, ObjectI, bool) }
Iterable is an interface that some objects might 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 Null ¶
type Null struct{}
Null wraps nothing and implements our ObjectI interface.
func (*Null) InvokeMethod ¶
func (n *Null) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Null) ToInterface ¶
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) Type ¶
func (n *Null) Type() objecttype.ObjectType
Type returns the type of this object.
type ObjectI ¶
type ObjectI interface { // Type returns the type of this object. Type() objecttype.ObjectType // Inspect returns a string-representation of the given object. Inspect() string // InvokeMethod invokes a method against the object. // (Built-in methods only.) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI // 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 implmenet.
type Regexp ¶
type Regexp struct { // Value holds the string value this object wraps. Value string // Flags holds the flags for the object Flags string }
Regexp wraps regular-expressions and implements the ObjectI interface.
func (*Regexp) InvokeMethod ¶
func (r *Regexp) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*Regexp) ToInterface ¶
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) Type ¶
func (r *Regexp) Type() objecttype.ObjectType
Type returns the type of this object.
type ReturnValue ¶
type ReturnValue struct { // Value is the object that is to be returned Value ObjectI }
ReturnValue wraps ObjectI and implements ObjectI interface.
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
Inspect returns a string-representation of the given object.
func (*ReturnValue) InvokeMethod ¶
func (rv *ReturnValue) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*ReturnValue) ToInterface ¶
func (rv *ReturnValue) 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 (*ReturnValue) Type ¶
func (rv *ReturnValue) Type() objecttype.ObjectType
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 ObjectI and Hashable interfaces.
func (*String) InvokeMethod ¶
func (s *String) InvokeMethod(method string, env Environment, args ...ObjectI) ObjectI
InvokeMethod invokes a method against the object. (Built-in methods only.)
func (*String) Next ¶
Next implements the Iterable interface, and allows the contents of our string to be iterated over.
func (*String) Reset ¶
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 ¶
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) Type ¶
func (s *String) Type() objecttype.ObjectType
Type returns the type of this object.