Skip to content

Commit

Permalink
修复Map
Browse files Browse the repository at this point in the history
  • Loading branch information
王广裕 committed Jun 15, 2023
1 parent 43475e4 commit 1afc7d1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tengo.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,23 @@ func ToInterface(o Object) (res interface{}) {
res.([]interface{})[i] = ToInterface(val)
}
case *Map:
res = orderedmap.New()
if len(o.keys) > 0 {
for _, key := range o.keys {
v, _ := o.Get(key)
res.(*orderedmap.OrderedMap).Set(key, ToInterface(v))
res = orderedmap.New()
if len(o.keys) > 0 {
for _, key := range o.keys {
v, _ := o.Get(key)
res.(*orderedmap.OrderedMap).Set(key, ToInterface(v))
}
}
}
if len(o.Value) > len(o.keys) {
if len(o.Value) > len(o.keys) {
for key, v := range o.Value {
res.(*orderedmap.OrderedMap).Set(key, ToInterface(v))
}
}
} else {
res = make(map[string]interface{})
for key, v := range o.Value {
res.(*orderedmap.OrderedMap).Set(key, ToInterface(v))
res.(map[string]interface{})[key] = ToInterface(v)
}
}
case *ImmutableMap:
Expand Down

0 comments on commit 1afc7d1

Please sign in to comment.