Skip to content

Commit

Permalink
Cast a class constructor's return value to an instance of the class
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Apr 28, 2017
1 parent 5814a17 commit f2dadfb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions ffi/unsafe/introspection.rkt
Expand Up @@ -650,10 +650,18 @@
(struct gi-object gi-registered-type ()
#:property prop:procedure
(lambda (object method-name . arguments)
(let ([method (gi-object-lookup-method object method-name)])
(if method
(apply method arguments)
(error "o no method not found")))))
(let* ([method (gi-object-lookup-method object method-name)]
[invocation (if method
(apply method arguments)
(error "o no method not found"))])
(if (and (gobject? invocation)
(memq 'constructor? (gi-function-flags method)))
(let ([base (gtype-instance-type invocation)])
;; If a method is a constructor and the return type is a
;; gobject, cast the return value to this class. This is
;; potentially controversial...
(cast invocation (gi-object->ctype base) (gi-object->ctype object)))
invocation))))

(struct gobject gtype-instance ())

Expand Down Expand Up @@ -709,7 +717,7 @@
(with-syntax ([method-name (string->symbol (string-replace
(symbol->string (syntax-e #'method-id))
"-" "_"))])
#'(and (gi-object-method-lookup (gtype-instance-type obj.c)
#'(and (gi-object-lookup-method (gtype-instance-type obj.c)
'method-name)
#t))]))

Expand Down
2 changes: 1 addition & 1 deletion gstreamer/main.rkt
Expand Up @@ -24,4 +24,4 @@

(define (pipeline-add-many pipeline . elements)
(for/and ([element elements])
(bin 'add pipeline element)))
(send pipeline add element)))

0 comments on commit f2dadfb

Please sign in to comment.