From 0b8e9a1495fc61f2628182678985ecd7a3439a72 Mon Sep 17 00:00:00 2001 From: JT Olio Date: Fri, 13 Oct 2023 02:04:10 -0400 Subject: [PATCH] switch Call to return reflect.Value instead of interface{} which is more general --- README.md | 2 +- reflect_helpers.go | 8 -------- troop_call.go | 4 ++-- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2764e13..015cd17 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ out, err := troop.Call("fmt.Fprintf", os.Stdout, "hello %s", []interface{}{"worl if err != nil { // some error calling the function return err } -n, err := out[0].(int), out[1].(error) +n, err := out[0].Int(), out[1].Interface().(error) if err != nil { return err } diff --git a/reflect_helpers.go b/reflect_helpers.go index aa5718f..7bb14d2 100644 --- a/reflect_helpers.go +++ b/reflect_helpers.go @@ -8,14 +8,6 @@ import ( "unsafe" ) -func ifaces(values []reflect.Value) []interface{} { - out := make([]interface{}, 0, len(values)) - for _, value := range values { - out = append(out, value.Interface()) - } - return out -} - func reflectCanBeNil(rtyp reflect.Type) bool { switch rtyp.Kind() { case reflect.Interface, diff --git a/troop_call.go b/troop_call.go index beeb054..93e8fa2 100644 --- a/troop_call.go +++ b/troop_call.go @@ -67,7 +67,7 @@ func (t *Troop) Functions() ([]string, error) { return out, nil } -func (t *Troop) Call(name string, args ...interface{}) ([]interface{}, error) { +func (t *Troop) Call(name string, args ...interface{}) ([]reflect.Value, error) { if err := t.check(); err != nil { return nil, err } @@ -103,7 +103,7 @@ func (t *Troop) Call(name string, args ...interface{}) ([]interface{}, error) { // make it happen fn_typ := reflect.FuncOf(in_types, out_types, false) fn := reflect.ValueOf(makeInterface(dataPtr(fn_typ), unsafe.Pointer(&pc))) - return ifaces(fn.Call(in)), nil + return fn.Call(in), nil } func (t *Troop) buildArguments(args []interface{}, dtypes []dwarf.Type) (