From: espen Date: Tue, 31 Jan 2006 14:02:51 +0000 (+0000) Subject: Added code to register new types with the gobject type system X-Git-Tag: clg-0-92~114 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/clg/commitdiff_plain/0a77b51f931ab1d7f0e99dfae3697a2997708430 Added code to register new types with the gobject type system --- diff --git a/glib/gtype.lisp b/glib/gtype.lisp index 93d124e..a1286ce 100644 --- a/glib/gtype.lisp +++ b/glib/gtype.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: gtype.lisp,v 1.32 2005/04/23 16:48:51 espen Exp $ +;; $Id: gtype.lisp,v 1.33 2006/01/31 14:02:51 espen Exp $ (in-package "GLIB") @@ -234,6 +234,40 @@ (defun default-type-init-name (type) (substitute #\_ #\- (string-downcase type))))) +(eval-when (:compile-toplevel :load-toplevel :execute) + (defclass type-info (struct) + ((class-size :allocation :alien :type (unsigned 16) :initarg :class-size) + (base-init :allocation :alien :type pointer) + (base-finalize :allocation :alien :type pointer) + (class-init :allocation :alien :type pointer) + (class-finalize :allocation :alien :type pointer) + (class-data :allocation :alien :type pointer) + (instance-size :allocation :alien :type (unsigned 16) + :initarg :instance-size) + (n-preallocs :allocation :alien :type (unsigned 16)) + (instance-init :allocation :alien :type pointer) + (value-table :allocation :alien :type pointer)) + (:metaclass struct-class))) + +(defbinding %type-register-static () type-number + (parent-type gtype) + (name string) + (info type-info) + (0 unsigned-int)) + +(defun register-new-type (type parent) + (let ((parent-info (type-query parent))) + (with-slots ((parent-number type-number) class-size instance-size) parent-info + (let ((type-number + (%type-register-static + parent-number + (default-alien-type-name type) + (make-instance 'type-info :class-size class-size :instance-size instance-size)))) + (setf (gethash type *lisp-type-to-type-number*) type-number) + (setf (gethash type-number *type-number-to-lisp-type*) type) + type-number)))) + + ;;;; Metaclass for subclasses of ginstance