forked from lug/matterbridge
36
vendor/github.com/d5/tengo/script/variable.go
generated
vendored
36
vendor/github.com/d5/tengo/script/variable.go
generated
vendored
@@ -9,7 +9,7 @@ import (
|
||||
// Variable is a user-defined variable for the script.
|
||||
type Variable struct {
|
||||
name string
|
||||
value *objects.Object
|
||||
value objects.Object
|
||||
}
|
||||
|
||||
// NewVariable creates a Variable.
|
||||
@@ -21,7 +21,7 @@ func NewVariable(name string, value interface{}) (*Variable, error) {
|
||||
|
||||
return &Variable{
|
||||
name: name,
|
||||
value: &obj,
|
||||
value: obj,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -32,18 +32,18 @@ func (v *Variable) Name() string {
|
||||
|
||||
// Value returns an empty interface of the variable value.
|
||||
func (v *Variable) Value() interface{} {
|
||||
return objectToInterface(*v.value)
|
||||
return objects.ToInterface(v.value)
|
||||
}
|
||||
|
||||
// ValueType returns the name of the value type.
|
||||
func (v *Variable) ValueType() string {
|
||||
return (*v.value).TypeName()
|
||||
return v.value.TypeName()
|
||||
}
|
||||
|
||||
// Int returns int value of the variable value.
|
||||
// It returns 0 if the value is not convertible to int.
|
||||
func (v *Variable) Int() int {
|
||||
c, _ := objects.ToInt(*v.value)
|
||||
c, _ := objects.ToInt(v.value)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (v *Variable) Int() int {
|
||||
// Int64 returns int64 value of the variable value.
|
||||
// It returns 0 if the value is not convertible to int64.
|
||||
func (v *Variable) Int64() int64 {
|
||||
c, _ := objects.ToInt64(*v.value)
|
||||
c, _ := objects.ToInt64(v.value)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (v *Variable) Int64() int64 {
|
||||
// Float returns float64 value of the variable value.
|
||||
// It returns 0.0 if the value is not convertible to float64.
|
||||
func (v *Variable) Float() float64 {
|
||||
c, _ := objects.ToFloat64(*v.value)
|
||||
c, _ := objects.ToFloat64(v.value)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (v *Variable) Float() float64 {
|
||||
// Char returns rune value of the variable value.
|
||||
// It returns 0 if the value is not convertible to rune.
|
||||
func (v *Variable) Char() rune {
|
||||
c, _ := objects.ToRune(*v.value)
|
||||
c, _ := objects.ToRune(v.value)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (v *Variable) Char() rune {
|
||||
// Bool returns bool value of the variable value.
|
||||
// It returns 0 if the value is not convertible to bool.
|
||||
func (v *Variable) Bool() bool {
|
||||
c, _ := objects.ToBool(*v.value)
|
||||
c, _ := objects.ToBool(v.value)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -83,11 +83,11 @@ func (v *Variable) Bool() bool {
|
||||
// Array returns []interface value of the variable value.
|
||||
// It returns 0 if the value is not convertible to []interface.
|
||||
func (v *Variable) Array() []interface{} {
|
||||
switch val := (*v.value).(type) {
|
||||
switch val := v.value.(type) {
|
||||
case *objects.Array:
|
||||
var arr []interface{}
|
||||
for _, e := range val.Value {
|
||||
arr = append(arr, objectToInterface(e))
|
||||
arr = append(arr, objects.ToInterface(e))
|
||||
}
|
||||
return arr
|
||||
}
|
||||
@@ -98,11 +98,11 @@ func (v *Variable) Array() []interface{} {
|
||||
// Map returns map[string]interface{} value of the variable value.
|
||||
// It returns 0 if the value is not convertible to map[string]interface{}.
|
||||
func (v *Variable) Map() map[string]interface{} {
|
||||
switch val := (*v.value).(type) {
|
||||
switch val := v.value.(type) {
|
||||
case *objects.Map:
|
||||
kv := make(map[string]interface{})
|
||||
for mk, mv := range val.Value {
|
||||
kv[mk] = objectToInterface(mv)
|
||||
kv[mk] = objects.ToInterface(mv)
|
||||
}
|
||||
return kv
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (v *Variable) Map() map[string]interface{} {
|
||||
// String returns string value of the variable value.
|
||||
// It returns 0 if the value is not convertible to string.
|
||||
func (v *Variable) String() string {
|
||||
c, _ := objects.ToString(*v.value)
|
||||
c, _ := objects.ToString(v.value)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (v *Variable) String() string {
|
||||
// Bytes returns a byte slice of the variable value.
|
||||
// It returns nil if the value is not convertible to byte slice.
|
||||
func (v *Variable) Bytes() []byte {
|
||||
c, _ := objects.ToByteSlice(*v.value)
|
||||
c, _ := objects.ToByteSlice(v.value)
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func (v *Variable) Bytes() []byte {
|
||||
// Error returns an error if the underlying value is error object.
|
||||
// If not, this returns nil.
|
||||
func (v *Variable) Error() error {
|
||||
err, ok := (*v.value).(*objects.Error)
|
||||
err, ok := v.value.(*objects.Error)
|
||||
if ok {
|
||||
return errors.New(err.String())
|
||||
}
|
||||
@@ -140,10 +140,10 @@ func (v *Variable) Error() error {
|
||||
// Object returns an underlying Object of the variable value.
|
||||
// Note that returned Object is a copy of an actual Object used in the script.
|
||||
func (v *Variable) Object() objects.Object {
|
||||
return *v.value
|
||||
return v.value
|
||||
}
|
||||
|
||||
// IsUndefined returns true if the underlying value is undefined.
|
||||
func (v *Variable) IsUndefined() bool {
|
||||
return *v.value == objects.UndefinedValue
|
||||
return v.value == objects.UndefinedValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user