summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/d5/tengo/objects/conversion.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-04-06 22:18:25 +0200
committerGitHub <noreply@github.com>2019-04-06 22:18:25 +0200
commit115d20373c21b107a428a55247c64f900e116038 (patch)
treec7299b3d3be2a48c0f2d5bfbd856cbd1b27d2e55 /vendor/github.com/d5/tengo/objects/conversion.go
parentcdf33e5748c110e12097130bdb44637e3d14b229 (diff)
downloadmatterbridge-msglm-115d20373c21b107a428a55247c64f900e116038.tar.gz
matterbridge-msglm-115d20373c21b107a428a55247c64f900e116038.tar.bz2
matterbridge-msglm-115d20373c21b107a428a55247c64f900e116038.zip
Update tengo vendor and load the stdlib. Fixes #789 (#792)
Diffstat (limited to 'vendor/github.com/d5/tengo/objects/conversion.go')
-rw-r--r--vendor/github.com/d5/tengo/objects/conversion.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/vendor/github.com/d5/tengo/objects/conversion.go b/vendor/github.com/d5/tengo/objects/conversion.go
index 714f2617..d7cb3a03 100644
--- a/vendor/github.com/d5/tengo/objects/conversion.go
+++ b/vendor/github.com/d5/tengo/objects/conversion.go
@@ -1,6 +1,7 @@
package objects
import (
+ "errors"
"fmt"
"strconv"
"time"
@@ -158,8 +159,8 @@ func ToTime(o Object) (v time.Time, ok bool) {
return
}
-// objectToInterface attempts to convert an object o to an interface{} value
-func objectToInterface(o Object) (res interface{}) {
+// ToInterface attempts to convert an object o to an interface{} value
+func ToInterface(o Object) (res interface{}) {
switch o := o.(type) {
case *Int:
res = o.Value
@@ -176,13 +177,29 @@ func objectToInterface(o Object) (res interface{}) {
case *Array:
res = make([]interface{}, len(o.Value))
for i, val := range o.Value {
- res.([]interface{})[i] = objectToInterface(val)
+ res.([]interface{})[i] = ToInterface(val)
+ }
+ case *ImmutableArray:
+ res = make([]interface{}, len(o.Value))
+ for i, val := range o.Value {
+ res.([]interface{})[i] = ToInterface(val)
}
case *Map:
res = make(map[string]interface{})
for key, v := range o.Value {
- res.(map[string]interface{})[key] = objectToInterface(v)
+ res.(map[string]interface{})[key] = ToInterface(v)
+ }
+ case *ImmutableMap:
+ res = make(map[string]interface{})
+ for key, v := range o.Value {
+ res.(map[string]interface{})[key] = ToInterface(v)
}
+ case *Time:
+ res = o.Value
+ case *Error:
+ res = errors.New(o.String())
+ case *Undefined:
+ res = nil
case Object:
return o
}