aboutsummaryrefslogtreecommitdiff
path: root/object/object.go
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-04-04 16:25:56 +0000
committerBobby <[email protected]>2024-04-04 16:25:56 +0000
commit77d0ea46b3f1de99357c7706c4c05eb44c237412 (patch)
treed6fa8ca0a89233b26591eaed72c1017ad6190dba /object/object.go
parent3d4f24f7c4ea05471109c0b13abbc95e70c6924b (diff)
downloadmana-77d0ea46b3f1de99357c7706c4c05eb44c237412.tar.xz
mana-77d0ea46b3f1de99357c7706c4c05eb44c237412.zip
arrays and array indexes
Diffstat (limited to 'object/object.go')
-rw-r--r--object/object.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/object/object.go b/object/object.go
index 24de9be..9fe896e 100644
--- a/object/object.go
+++ b/object/object.go
@@ -18,6 +18,7 @@ const (
STRING_OBJ = "STRING"
ERROR_OBJ = "ERROR"
BUILTIN_OBJ = "BUILTIN"
+ ARRAY_OBJ = "ARRAY"
)
type Object interface {
@@ -59,6 +60,10 @@ type Builtin struct {
Fn BuiltinFunction
}
+type Array struct {
+ Elements []Object
+}
+
func (i *Integer) Type() ObjectType {
return INTEGER_OBJ
}
@@ -122,3 +127,20 @@ func (s *String) Inspect() string { return s.Value }
func (b *Builtin) Type() ObjectType { return BUILTIN_OBJ }
func (b *Builtin) Inspect() string { return "builtin function" }
+
+func (ao *Array) Type() ObjectType { return ARRAY_OBJ }
+func (ao *Array) Inspect() string {
+ var out bytes.Buffer
+
+ elements := []string{}
+
+ for _, el := range ao.Elements {
+ elements = append(elements, el.Inspect())
+ }
+
+ out.WriteString("[")
+ out.WriteString(strings.Join(elements, ", "))
+ out.WriteString("]")
+
+ return out.String()
+}