Call executes a method receiver's named internal method, passing a slice of values as arguments to the method. If the method fails to execute or returns no value, nil is returned, otherwise a Value instance is returned.
(name string, args []interface{})
| 126 | // values as arguments to the method. If the method fails to execute or returns |
| 127 | // no value, nil is returned, otherwise a Value instance is returned. |
| 128 | func (o *ReceiverObject) Call(name string, args []interface{}) *Value { |
| 129 | if _, exists := o.methods[name]; !exists { |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | in := make([]reflect.Value, 0) |
| 134 | for _, v := range args { |
| 135 | in = append(in, reflect.ValueOf(v)) |
| 136 | } |
| 137 | |
| 138 | // Call receiver method. |
| 139 | var result interface{} |
| 140 | val := o.methods[name].Call(in) |
| 141 | |
| 142 | // Process results, returning a single value if result slice contains a single |
| 143 | // element, otherwise returns a slice of values. |
| 144 | if len(val) > 1 { |
| 145 | t := make([]interface{}, len(val)) |
| 146 | for i, v := range val { |
| 147 | t[i] = v.Interface() |
| 148 | } |
| 149 | |
| 150 | result = t |
| 151 | } else if len(val) == 1 { |
| 152 | result = val[0].Interface() |
| 153 | } else { |
| 154 | return nil |
| 155 | } |
| 156 | |
| 157 | v, err := NewValue(result) |
| 158 | if err != nil { |
| 159 | return nil |
| 160 | } |
| 161 | |
| 162 | return v |
| 163 | } |
no test coverage detected