Skip to content

Commit

Permalink
Support returning any from callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
eatonphil committed May 13, 2022
1 parent aa1e904 commit c8e28af
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions callback.go
Expand Up @@ -353,13 +353,27 @@ 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:
errorInterface := reflect.TypeOf((*error)(nil)).Elem()
if typ.Implements(errorInterface) {
return callbackRetNil, nil
}

if typ.NumMethods() == 0 {
return callbackRetAny, nil
}

fallthrough
case reflect.Slice:
if typ.Elem().Kind() != reflect.Uint8 {
Expand Down

0 comments on commit c8e28af

Please sign in to comment.