diff --git a/callback.go b/callback.go index b020fe37..808160d4 100644 --- a/callback.go +++ b/callback.go @@ -353,6 +353,15 @@ func callbackRetNil(ctx *C.sqlite3_context, v reflect.Value) error { return nil } +func callbackRetAny(ctx *C.sqlite3_context, v reflect.Value) error { + cb, err := callbackRet(v.Elem().Type()) + if err != nil { + return err + } + + return cb(ctx, v.Elem()) +} + func callbackRet(typ reflect.Type) (callbackRetConverter, error) { switch typ.Kind() { case reflect.Interface: @@ -360,6 +369,11 @@ func callbackRet(typ reflect.Type) (callbackRetConverter, error) { if typ.Implements(errorInterface) { return callbackRetNil, nil } + + if typ.NumMethod() == 0 { + return callbackRetAny, nil + } + fallthrough case reflect.Slice: if typ.Elem().Kind() != reflect.Uint8 { diff --git a/callback_test.go b/callback_test.go index 714ed607..b09122ae 100644 --- a/callback_test.go +++ b/callback_test.go @@ -102,3 +102,15 @@ func TestCallbackConverters(t *testing.T) { } } } + +func TestCallbackReturnAny(t *testing.T) { + udf := func() interface{} { + return 1 + } + + typ := reflect.TypeOf(udf) + _, err := callbackRet(typ.Out(0)) + if err != nil { + t.Errorf("Expected valid callback for any return type, got: %s", err) + } +}