X-Git-Url: https://git.jsancho.org/?p=guile-irrlicht.git;a=blobdiff_plain;f=Swig%2Fcommon.scm;fp=Swig%2Fcommon.scm;h=a647f429c89b9b7c9b852e01c194f4a5f58cadf1;hp=0000000000000000000000000000000000000000;hb=d392bfc335713faab44275624d8fd78139880975;hpb=3bb58c2b45af12c0f9c9eac648e67ac6fa90e104 diff --git a/Swig/common.scm b/Swig/common.scm new file mode 100644 index 0000000..a647f42 --- /dev/null +++ b/Swig/common.scm @@ -0,0 +1,70 @@ +;;;************************************************************************ +;;;*common.scm +;;;* +;;;* This file contains generic SWIG GOOPS classes for generated +;;;* GOOPS file support +;;;************************************************************************ + +(define-module (Swig swigrun)) + +(define-module (Swig common) + #:use-module (oop goops) + #:use-module (Swig swigrun)) + +(define-class () + (new-function #:init-value #f)) + +(define-method (initialize (class ) initargs) + (next-method) + (slot-set! class 'new-function (get-keyword #:new-function initargs #f))) + +(define-class () + (swig-smob #:init-value #f) + #:metaclass +) + +(define-method (initialize (obj ) initargs) + (next-method) + (slot-set! obj 'swig-smob + (let ((arg (get-keyword #:init-smob initargs #f))) + (if arg + arg + (let ((ret (apply (slot-ref (class-of obj) 'new-function) (get-keyword #:args initargs '())))) + ;; if the class is registered with runtime environment, + ;; new-Function will return a goops class. In that case, extract the smob + ;; from that goops class and set it as the current smob. + (if (slot-exists? ret 'swig-smob) + (slot-ref ret 'swig-smob) + ret)))))) + +(define (display-address o file) + (display (number->string (object-address o) 16) file)) + +(define (display-pointer-address o file) + ;; Don't fail if the function SWIG-PointerAddress is not present. + (let ((address (false-if-exception (SWIG-PointerAddress o)))) + (if address + (begin + (display " @ " file) + (display (number->string address 16) file))))) + +(define-method (write (o ) file) + ;; We display _two_ addresses to show the object's identity: + ;; * first the address of the GOOPS proxy object, + ;; * second the pointer address. + ;; The reason is that proxy objects are created and discarded on the + ;; fly, so different proxy objects for the same C object will appear. + (let ((class (class-of o))) + (if (slot-bound? class 'name) + (begin + (display "#<" file) + (display (class-name class) file) + (display #\space file) + (display-address o file) + (display-pointer-address o file) + (display ">" file)) + (next-method)))) + +(export ) + +;;; common.scm ends here