diff options
| author | Bobby <[email protected]> | 2024-04-04 14:29:40 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-04-04 14:29:40 +0000 |
| commit | 98b3baa1d9d05551948b6657b4130cf05c11934d (patch) | |
| tree | c9ff7cc56f26e6481f0ca0cd74bae4f64abe53b0 /evaluator/builtins.go | |
| parent | 2f28a8de055029c4501a8cfb796e7f4a1af8b719 (diff) | |
| download | mana-98b3baa1d9d05551948b6657b4130cf05c11934d.tar.xz mana-98b3baa1d9d05551948b6657b4130cf05c11934d.zip | |
built in functions
Diffstat (limited to 'evaluator/builtins.go')
| -rw-r--r-- | evaluator/builtins.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/evaluator/builtins.go b/evaluator/builtins.go new file mode 100644 index 0000000..0e6846a --- /dev/null +++ b/evaluator/builtins.go @@ -0,0 +1,23 @@ +package evaluator + +import ( + "mana/object" +) + +var builtins = map[string]*object.Builtin{ + "len": { + Fn: func(args ...object.Object) object.Object { + if len(args) != 1 { + return newError("wrong number of arguments. got=%d, want=1", + len(args)) + } + + switch arg := args[0].(type) { + case *object.String: + return &object.Integer{Value: int64(len(arg.Value))} + default: + return newError("argument to `len` not supported, got %s", arg.Type()) + } + }, + }, +} |
