Skip to content

Commit

Permalink
Added GInterface instances for functions like gio_file_new_for-path
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalimehtar committed Jan 4, 2018
1 parent b11424f commit 12f8910
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ To get C pointer to an object, use this-of.
It is possible to make an object from a pointer:

```racket
(defvar *window-from-ptr* (funcall (gir:nget *gtk* "Window") window-ptr))
(defvar *window-from-ptr* (gir:build-object-ptr (gir:nget *gtk* "Window") window-ptr))
```

`window-ptr` should be `cffi:foreign-pointer` here.
Expand Down
14 changes: 13 additions & 1 deletion src/object.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
(defmethod build-interface ((info object-info))
(make-instance 'object-class :info info))

(defmethod build-interface ((info interface-info))
(make-instance 'interface-desc :info info))

(defun object-class-get-constructor-class-function-info (object-class cname)
(let* ((info (info-of object-class))
(function-info (object-info-find-method info cname))
Expand Down Expand Up @@ -136,10 +139,14 @@
(tg:finalize this (lambda () (g-object-unref (cffi:make-pointer a)))))
object)

(defgeneric find-build-method (object-class cname))
(defmethod find-build-method ((object-class object-class) cname)
(object-class-find-build-method object-class cname))

(defmethod nsget ((object object-instance) name)
(let* ((object-class (gir-class-of object))
(cname (c-name name))
(method (object-class-find-build-method object-class cname))
(method (find-build-method object-class cname))
(this (this-of object)))
(lambda (&rest args)
(apply method (cons this args)))))
Expand Down Expand Up @@ -244,6 +251,11 @@
(defclass interface-desc ()
((info :initarg :info :reader info-of)))

(defmethod find-build-method ((object-class interface-desc) cname)
(let ((func-info (interface-info-find-method
(info-of object-class) cname)))
(and func-info (build-function func-info))))

(defmethod print-object ((interface-desc interface-desc) s)
(format s "I<~a>" (info-get-name (info-of interface-desc))))

Expand Down
1 change: 1 addition & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
#:typelib-free

#:build-translator
#:build-object-ptr

#:ffi #:require-namespace
#:nget
Expand Down

0 comments on commit 12f8910

Please sign in to comment.