MCPcopy Create free account
hub / github.com/d5/tengo / Object

Interface Object

objects.go:27–80  ·  view source on GitHub ↗

Object represents an object in the VM.

Source from the content-addressed store, hash-verified

25
26// Object represents an object in the VM.
27type Object interface {
28 // TypeName should return the name of the type.
29 TypeName() string
30
31 // String should return a string representation of the type's value.
32 String() string
33
34 // BinaryOp should return another object that is the result of a given
35 // binary operator and a right-hand side object. If BinaryOp returns an
36 // error, the VM will treat it as a run-time error.
37 BinaryOp(op token.Token, rhs Object) (Object, error)
38
39 // IsFalsy should return true if the value of the type should be considered
40 // as falsy.
41 IsFalsy() bool
42
43 // Equals should return true if the value of the type should be considered
44 // as equal to the value of another object.
45 Equals(another Object) bool
46
47 // Copy should return a copy of the type (and its value). Copy function
48 // will be used for copy() builtin function which is expected to deep-copy
49 // the values generally.
50 Copy() Object
51
52 // IndexGet should take an index Object and return a result Object or an
53 // error for indexable objects. Indexable is an object that can take an
54 // index and return an object. If error is returned, the runtime will treat
55 // it as a run-time error and ignore returned value. If Object is not
56 // indexable, ErrNotIndexable should be returned as error. If nil is
57 // returned as value, it will be converted to UndefinedToken value by the
58 // runtime.
59 IndexGet(index Object) (value Object, err error)
60
61 // IndexSet should take an index Object and a value Object for index
62 // assignable objects. Index assignable is an object that can take an index
63 // and a value on the left-hand side of the assignment statement. If Object
64 // is not index assignable, ErrNotIndexAssignable should be returned as
65 // error. If an error is returned, it will be treated as a run-time error.
66 IndexSet(index, value Object) error
67
68 // Iterate should return an Iterator for the type.
69 Iterate() Iterator
70
71 // CanIterate should return whether the Object can be Iterated.
72 CanIterate() bool
73
74 // Call should take an arbitrary number of arguments and returns a return
75 // value and/or an error, which the VM will consider as a run-time error.
76 Call(args ...Object) (ret Object, err error)
77
78 // CanCall should return whether the Object can be Called.
79 CanCall() bool
80}
81
82// ObjectImpl represents a default Object Implementation. To defined a new
83// value type, one can embed ObjectImpl in their type declarations to avoid

Callers 49

TestObject_TypeNameFunction · 0.95
runMethod · 0.95
builtinTypeNameFunction · 0.65
builtinLenFunction · 0.65
builtinRangeFunction · 0.65
builtinFormatFunction · 0.65
builtinAppendFunction · 0.65
builtinDeleteFunction · 0.65
TestObject_StringFunction · 0.95
formatGlobalsFunction · 0.65
badVerbMethod · 0.65
printArgMethod · 0.65

Implementers 2

StringArrayvm_test.go
ObjectImplobjects.go

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…