Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.6 KiB

  1. ;;;************************************************************************
  2. ;;;*common.scm
  3. ;;;*
  4. ;;;* This file contains generic SWIG GOOPS classes for generated
  5. ;;;* GOOPS file support
  6. ;;;*
  7. ;;;* Copyright (C) 2003 John Lenz ([email protected])
  8. ;;;* Copyright (C) 2004 Matthias Koeppe ([email protected])
  9. ;;;*
  10. ;;;* This file may be freely redistributed without license or fee provided
  11. ;;;* this copyright message remains intact.
  12. ;;;************************************************************************
  13. (define-module (Swig swigrun))
  14. (define-module (Swig common)
  15. #:use-module (oop goops)
  16. #:use-module (Swig swigrun))
  17. (define-class <swig-metaclass> (<class>)
  18. (new-function #:init-value #f))
  19. (define-method (initialize (class <swig-metaclass>) initargs)
  20. (slot-set! class 'new-function (get-keyword #:new-function initargs #f))
  21. (next-method))
  22. (define-class <swig> ()
  23. (swig-smob #:init-value #f)
  24. #:metaclass <swig-metaclass>
  25. )
  26. (define-method (initialize (obj <swig>) initargs)
  27. (next-method)
  28. (slot-set! obj 'swig-smob
  29. (let ((arg (get-keyword #:init-smob initargs #f)))
  30. (if arg
  31. arg
  32. (let ((ret (apply (slot-ref (class-of obj) 'new-function) (get-keyword #:args initargs '()))))
  33. ;; if the class is registered with runtime environment,
  34. ;; new-Function will return a <swig> goops class. In that case, extract the smob
  35. ;; from that goops class and set it as the current smob.
  36. (if (slot-exists? ret 'swig-smob)
  37. (slot-ref ret 'swig-smob)
  38. ret))))))
  39. (define (display-address o file)
  40. (display (number->string (object-address o) 16) file))
  41. (define (display-pointer-address o file)
  42. ;; Don't fail if the function SWIG-PointerAddress is not present.
  43. (let ((address (false-if-exception (SWIG-PointerAddress o))))
  44. (if address
  45. (begin
  46. (display " @ " file)
  47. (display (number->string address 16) file)))))
  48. (define-method (write (o <swig>) file)
  49. ;; We display _two_ addresses to show the object's identity:
  50. ;; * first the address of the GOOPS proxy object,
  51. ;; * second the pointer address.
  52. ;; The reason is that proxy objects are created and discarded on the
  53. ;; fly, so different proxy objects for the same C object will appear.
  54. (let ((class (class-of o)))
  55. (if (slot-bound? class 'name)
  56. (begin
  57. (display "#<" file)
  58. (display (class-name class) file)
  59. (display #\space file)
  60. (display-address o file)
  61. (display-pointer-address o file)
  62. (display ">" file))
  63. (next-method))))
  64. (export <swig-metaclass> <swig>)
  65. ;;; common.scm ends here