summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/d5
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/d5')
-rw-r--r--vendor/github.com/d5/tengo/v2/.goreleaser.yml7
-rw-r--r--vendor/github.com/d5/tengo/v2/README.md5
-rw-r--r--vendor/github.com/d5/tengo/v2/builtins.go109
-rw-r--r--vendor/github.com/d5/tengo/v2/vm.go6
4 files changed, 120 insertions, 7 deletions
diff --git a/vendor/github.com/d5/tengo/v2/.goreleaser.yml b/vendor/github.com/d5/tengo/v2/.goreleaser.yml
index 1bd14324..a86ce7e0 100644
--- a/vendor/github.com/d5/tengo/v2/.goreleaser.yml
+++ b/vendor/github.com/d5/tengo/v2/.goreleaser.yml
@@ -11,9 +11,10 @@ builds:
- darwin
- linux
- windows
-archive:
- files:
- - none*
+archives:
+ -
+ files:
+ - none*
checksum:
name_template: 'checksums.txt'
changelog:
diff --git a/vendor/github.com/d5/tengo/v2/README.md b/vendor/github.com/d5/tengo/v2/README.md
index 92277cfe..f170be24 100644
--- a/vendor/github.com/d5/tengo/v2/README.md
+++ b/vendor/github.com/d5/tengo/v2/README.md
@@ -7,7 +7,6 @@
[![GoDoc](https://godoc.org/github.com/d5/tengo?status.svg)](https://godoc.org/github.com/d5/tengo)
[![Go Report Card](https://goreportcard.com/badge/github.com/d5/tengo)](https://goreportcard.com/report/github.com/d5/tengo)
[![CircleCI](https://circleci.com/gh/d5/tengo.svg?style=svg)](https://circleci.com/gh/d5/tengo)
-[![Sourcegraph](https://sourcegraph.com/github.com/d5/tengo/-/badge.svg)](https://sourcegraph.com/github.com/d5/tengo?badge)
**Tengo is a small, dynamic, fast, secure script language for Go.**
@@ -75,6 +74,10 @@ _* See [here](https://github.com/d5/tengobench) for commands/codes used_
## Quick Start
+```
+go get github.com/d5/tengo/v2
+```
+
A simple Go example code that compiles/runs Tengo script code with some input/output values:
```golang
diff --git a/vendor/github.com/d5/tengo/v2/builtins.go b/vendor/github.com/d5/tengo/v2/builtins.go
index 87f7fc3d..fcda81cd 100644
--- a/vendor/github.com/d5/tengo/v2/builtins.go
+++ b/vendor/github.com/d5/tengo/v2/builtins.go
@@ -14,6 +14,14 @@ var builtinFuncs = []*BuiltinFunction{
Value: builtinAppend,
},
{
+ Name: "delete",
+ Value: builtinDelete,
+ },
+ {
+ Name: "splice",
+ Value: builtinSplice,
+ },
+ {
Name: "string",
Value: builtinString,
},
@@ -500,3 +508,104 @@ func builtinAppend(args ...Object) (Object, error) {
}
}
}
+
+// builtinDelete deletes Map keys
+// usage: delete(map, "key")
+// key must be a string
+func builtinDelete(args ...Object) (Object, error) {
+ argsLen := len(args)
+ if argsLen != 2 {
+ return nil, ErrWrongNumArguments
+ }
+ switch arg := args[0].(type) {
+ case *Map:
+ if key, ok := args[1].(*String); ok {
+ delete(arg.Value, key.Value)
+ return UndefinedValue, nil
+ }
+ return nil, ErrInvalidArgumentType{
+ Name: "second",
+ Expected: "string",
+ Found: args[1].TypeName(),
+ }
+ default:
+ return nil, ErrInvalidArgumentType{
+ Name: "first",
+ Expected: "map",
+ Found: arg.TypeName(),
+ }
+ }
+}
+
+// builtinSplice deletes and changes given Array, returns deleted items.
+// usage:
+// deleted_items := splice(array[,start[,delete_count[,item1[,item2[,...]]]])
+func builtinSplice(args ...Object) (Object, error) {
+ argsLen := len(args)
+ if argsLen == 0 {
+ return nil, ErrWrongNumArguments
+ }
+
+ array, ok := args[0].(*Array)
+ if !ok {
+ return nil, ErrInvalidArgumentType{
+ Name: "first",
+ Expected: "array",
+ Found: args[0].TypeName(),
+ }
+ }
+ arrayLen := len(array.Value)
+
+ var startIdx int
+ if argsLen > 1 {
+ arg1, ok := args[1].(*Int)
+ if !ok {
+ return nil, ErrInvalidArgumentType{
+ Name: "second",
+ Expected: "int",
+ Found: args[1].TypeName(),
+ }
+ }
+ startIdx = int(arg1.Value)
+ if startIdx < 0 || startIdx > arrayLen {
+ return nil, ErrIndexOutOfBounds
+ }
+ }
+
+ delCount := len(array.Value)
+ if argsLen > 2 {
+ arg2, ok := args[2].(*Int)
+ if !ok {
+ return nil, ErrInvalidArgumentType{
+ Name: "third",
+ Expected: "int",
+ Found: args[2].TypeName(),
+ }
+ }
+ delCount = int(arg2.Value)
+ if delCount < 0 {
+ return nil, ErrIndexOutOfBounds
+ }
+ }
+ // if count of to be deleted items is bigger than expected, truncate it
+ if startIdx+delCount > arrayLen {
+ delCount = arrayLen - startIdx
+ }
+ // delete items
+ endIdx := startIdx + delCount
+ deleted := append([]Object{}, array.Value[startIdx:endIdx]...)
+
+ head := array.Value[:startIdx]
+ var items []Object
+ if argsLen > 3 {
+ items = make([]Object, 0, argsLen-3)
+ for i := 3; i < argsLen; i++ {
+ items = append(items, args[i])
+ }
+ }
+ items = append(items, array.Value[endIdx:]...)
+ array.Value = append(head, items...)
+
+ // return deleted items
+ return &Array{Value: deleted}, nil
+}
diff --git a/vendor/github.com/d5/tengo/v2/vm.go b/vendor/github.com/d5/tengo/v2/vm.go
index 783a54a9..af8783f0 100644
--- a/vendor/github.com/d5/tengo/v2/vm.go
+++ b/vendor/github.com/d5/tengo/v2/vm.go
@@ -80,14 +80,14 @@ func (v *VM) Run() (err error) {
if err != nil {
filePos := v.fileSet.Position(
v.curFrame.fn.SourcePos(v.ip - 1))
- err = fmt.Errorf("Runtime Error: %s\n\tat %s",
- err.Error(), filePos)
+ err = fmt.Errorf("Runtime Error: %w\n\tat %s",
+ err, filePos)
for v.framesIndex > 1 {
v.framesIndex--
v.curFrame = &v.frames[v.framesIndex-1]
filePos = v.fileSet.Position(
v.curFrame.fn.SourcePos(v.curFrame.ip - 1))
- err = fmt.Errorf("%s\n\tat %s", err.Error(), filePos)
+ err = fmt.Errorf("%w\n\tat %s", err, filePos)
}
return err
}