From 99987057f1dd94886b60e9bb125ec8eb053d5be9 Mon Sep 17 00:00:00 2001 From: Alexis Viscogliosi Date: Fri, 1 Sep 2023 07:51:42 +0200 Subject: [PATCH] invoke: add way to retrieve return values of an invoke --- invoke.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/invoke.go b/invoke.go index 8a70121a..dc16f55b 100644 --- a/invoke.go +++ b/invoke.go @@ -38,7 +38,8 @@ type invokeOptions struct { // InvokeInfo provides information about an Invoke. type InvokeInfo struct { - Inputs []*Input + Inputs []*Input + ReturnValues []*reflect.Value } // FillInvokeInfo is an InvokeOption that writes information on the types @@ -161,6 +162,13 @@ func (s *Scope) Invoke(function interface{}, opts ...InvokeOption) (err error) { if len(returned) == 0 { return nil } + + if options.Info != nil { + options.Info.ReturnValues = make([]*reflect.Value, len(returned)) + for i, v := range returned { + options.Info.ReturnValues[i] = &v + } + } if last := returned[len(returned)-1]; isError(last.Type()) { if err, _ := last.Interface().(error); err != nil { return err