From 0f2d8a599c6b3f2ee6cba4d0d887fe021df84ca6 Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 28 Mar 2020 23:41:35 +0100 Subject: [PATCH] Update vendor d5/tengo (#1066) --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/d5/tengo/v2/.goreleaser.yml | 7 +- vendor/github.com/d5/tengo/v2/README.md | 5 +- vendor/github.com/d5/tengo/v2/builtins.go | 109 ++++++++++++++++++ vendor/github.com/d5/tengo/v2/vm.go | 6 +- vendor/modules.txt | 2 +- 7 files changed, 124 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 63ed540d..272958cf 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Jeffail/gabs v1.1.1 // indirect github.com/Philipp15b/go-steam v1.0.1-0.20190816133340-b04c5a83c1c0 github.com/Rhymen/go-whatsapp v0.1.0 - github.com/d5/tengo/v2 v2.0.2 + github.com/d5/tengo/v2 v2.1.2 github.com/dfordsoft/golib v0.0.0-20180902042739-76ee6ab99bec github.com/fsnotify/fsnotify v1.4.7 github.com/go-telegram-bot-api/telegram-bot-api v4.6.5-0.20181225215658-ec221ba9ea45+incompatible diff --git a/go.sum b/go.sum index d7770880..e4db1b30 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,8 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/d5/tengo/v2 v2.0.2 h1:3APkPZPc1FExaJoWrN5YzvDqc6GNkQH6ehmCRDmN83I= -github.com/d5/tengo/v2 v2.0.2/go.mod h1:XRGjEs5I9jYIKTxly6HCF8oiiilk5E/RYXOZ5b0DZC8= +github.com/d5/tengo/v2 v2.1.2 h1:JR5O6qJW2GW9lpv/MfEqK16a/Wpp2y8I0JZZ5fqNOL0= +github.com/d5/tengo/v2 v2.1.2/go.mod h1:XRGjEs5I9jYIKTxly6HCF8oiiilk5E/RYXOZ5b0DZC8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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 @@ -13,6 +13,14 @@ var builtinFuncs = []*BuiltinFunction{ Name: "append", 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 } diff --git a/vendor/modules.txt b/vendor/modules.txt index 05336076..75549d7a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -23,7 +23,7 @@ github.com/Rhymen/go-whatsapp/binary/token github.com/Rhymen/go-whatsapp/crypto/cbc github.com/Rhymen/go-whatsapp/crypto/curve25519 github.com/Rhymen/go-whatsapp/crypto/hkdf -# github.com/d5/tengo/v2 v2.0.2 +# github.com/d5/tengo/v2 v2.1.2 github.com/d5/tengo/v2 github.com/d5/tengo/v2/parser github.com/d5/tengo/v2/stdlib