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.

103 lines
3.2 KiB

  1. /* Define a C preprocessor symbol that can be used in interface files
  2. to distinguish between the SWIG language modules. */
  3. #define SWIG_UFFI
  4. /* Typespecs for basic types. */
  5. %typemap(ffitype) char ":char";
  6. %typemap(ffitype) unsigned char ":unsigned-char";
  7. %typemap(ffitype) signed char ":char";
  8. %typemap(ffitype) short ":short";
  9. %typemap(ffitype) signed short ":short";
  10. %typemap(ffitype) unsigned short ":unsigned-short";
  11. %typemap(ffitype) int ":int";
  12. %typemap(ffitype) signed int ":int";
  13. %typemap(ffitype) unsigned int ":unsigned-int";
  14. %typemap(ffitype) long ":long";
  15. %typemap(ffitype) signed long ":long";
  16. %typemap(ffitype) unsigned long ":unsigned-long";
  17. %typemap(ffitype) float ":float";
  18. %typemap(ffitype) double ":double";
  19. %typemap(ffitype) char * ":cstring";
  20. %typemap(ffitype) void * ":pointer-void";
  21. %typemap(ffitype) void ":void";
  22. // FIXME: This is guesswork
  23. typedef long size_t;
  24. %wrapper %{
  25. ;; $Id: uffi.swg 7358 2005-08-09 15:09:15Z mkoeppe $
  26. (eval-when (compile eval)
  27. ;;; You can define your own identifier converter if you want.
  28. ;;; Use the -identifier-converter command line argument to
  29. ;;; specify its name.
  30. (defun identifier-convert-null (id &key type)
  31. (declare (ignore type))
  32. (read-from-string id))
  33. (defun identifier-convert-lispify (cname &key type)
  34. (assert (stringp cname))
  35. (if (eq type :constant)
  36. (setf cname (format nil "*~A*" cname)))
  37. (setf cname (replace-regexp cname "_" "-"))
  38. (let ((lastcase :other)
  39. newcase char res)
  40. (dotimes (n (length cname))
  41. (setf char (schar cname n))
  42. (if* (alpha-char-p char)
  43. then
  44. (setf newcase (if (upper-case-p char) :upper :lower))
  45. (when (or (and (eq lastcase :upper) (eq newcase :lower))
  46. (and (eq lastcase :lower) (eq newcase :upper)))
  47. ;; case change... add a dash
  48. (push #\- res)
  49. (setf newcase :other))
  50. (push (char-downcase char) res)
  51. (setf lastcase newcase)
  52. else
  53. (push char res)
  54. (setf lastcase :other)))
  55. (read-from-string (coerce (nreverse res) 'string))))
  56. (defun identifier-convert-low-level (cname &key type)
  57. (assert (stringp cname))
  58. (if (eq type :constant)
  59. (setf cname (format nil "+~A+" cname)))
  60. (setf cname (substitute #\- #\_ cname))
  61. (if (eq type :operator)
  62. (setf cname (format nil "%~A" cname)))
  63. (if (eq type :constant-function)
  64. nil)
  65. (read-from-string cname))
  66. (defmacro swig-defconstant (string value &key (export T))
  67. (let ((symbol (funcall *swig-identifier-converter* string :type :constant)))
  68. `(eval-when (compile load eval)
  69. (uffi:def-constant ,symbol ,value ,export))))
  70. (defmacro swig-defun (name &rest rest)
  71. (let ((symbol (funcall *swig-identifier-converter* name :type :operator)))
  72. `(eval-when (compile load eval)
  73. (uffi:def-function (,name ,symbol) ,@rest)
  74. (export (quote ,symbol)))))
  75. (defmacro swig-def-struct (name &rest fields)
  76. "Declare a struct object"
  77. (let ((symbol (funcall *swig-identifier-converter* name :type :type)))
  78. `(eval-when (compile load eval)
  79. (uffi:def-struct ,symbol ,@fields)
  80. (export (quote ,symbol)))))
  81. ) ;; eval-when
  82. %}