PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/guile/common.scm

#
Lisp | 70 lines | 43 code | 11 blank | 16 comment | 0 complexity | b0f17388ccd067039a4179da43f3f5b5 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. ;;;************************************************************************
  2. ;;;*common.scm
  3. ;;;*
  4. ;;;* This file contains generic SWIG GOOPS classes for generated
  5. ;;;* GOOPS file support
  6. ;;;************************************************************************
  7. (define-module (Swig swigrun))
  8. (define-module (Swig common)
  9. #:use-module (oop goops)
  10. #:use-module (Swig swigrun))
  11. (define-class <swig-metaclass> (<class>)
  12. (new-function #:init-value #f))
  13. (define-method (initialize (class <swig-metaclass>) initargs)
  14. (slot-set! class 'new-function (get-keyword #:new-function initargs #f))
  15. (next-method))
  16. (define-class <swig> ()
  17. (swig-smob #:init-value #f)
  18. #:metaclass <swig-metaclass>
  19. )
  20. (define-method (initialize (obj <swig>) initargs)
  21. (next-method)
  22. (slot-set! obj 'swig-smob
  23. (let ((arg (get-keyword #:init-smob initargs #f)))
  24. (if arg
  25. arg
  26. (let ((ret (apply (slot-ref (class-of obj) 'new-function) (get-keyword #:args initargs '()))))
  27. ;; if the class is registered with runtime environment,
  28. ;; new-Function will return a <swig> goops class. In that case, extract the smob
  29. ;; from that goops class and set it as the current smob.
  30. (if (slot-exists? ret 'swig-smob)
  31. (slot-ref ret 'swig-smob)
  32. ret))))))
  33. (define (display-address o file)
  34. (display (number->string (object-address o) 16) file))
  35. (define (display-pointer-address o file)
  36. ;; Don't fail if the function SWIG-PointerAddress is not present.
  37. (let ((address (false-if-exception (SWIG-PointerAddress o))))
  38. (if address
  39. (begin
  40. (display " @ " file)
  41. (display (number->string address 16) file)))))
  42. (define-method (write (o <swig>) file)
  43. ;; We display _two_ addresses to show the object's identity:
  44. ;; * first the address of the GOOPS proxy object,
  45. ;; * second the pointer address.
  46. ;; The reason is that proxy objects are created and discarded on the
  47. ;; fly, so different proxy objects for the same C object will appear.
  48. (let ((class (class-of o)))
  49. (if (slot-bound? class 'name)
  50. (begin
  51. (display "#<" file)
  52. (display (class-name class) file)
  53. (display #\space file)
  54. (display-address o file)
  55. (display-pointer-address o file)
  56. (display ">" file))
  57. (next-method))))
  58. (export <swig-metaclass> <swig>)
  59. ;;; common.scm ends here