PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/r_legacy.i

#
Swig | 98 lines | 76 code | 21 blank | 1 comment | 0 complexity | 996433ceec162edac329eecb4f625506 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module r_legacy
  2. %inline %{
  3. typedef char *String;
  4. typedef struct {
  5. int i;
  6. double d;
  7. char *str;
  8. String s;
  9. } Obj;
  10. Obj *getObject(int i, double d);
  11. #include <string.h>
  12. Obj *
  13. getObject(int i, double d)
  14. {
  15. const char *test_string = "a test string";
  16. Obj *obj;
  17. obj = (Obj *) calloc(1, sizeof(Obj));
  18. obj->i = i;
  19. obj->d = d;
  20. /* allocate one extra byte for the null */
  21. obj->str = (char *)malloc(strlen(test_string) + 1);
  22. strcpy(obj->str, test_string);
  23. return(obj);
  24. }
  25. %}
  26. char *getString();
  27. int getInt();
  28. double getDouble();
  29. float getFloat();
  30. long getLong();
  31. unsigned long getUnsignedLong();
  32. char getChar();
  33. extern unsigned long MyULong;
  34. extern const double PiSquared;
  35. #if 0
  36. extern float *MyFloatRef;
  37. #endif
  38. %inline %{
  39. #define PI 3.14159265358979
  40. unsigned long MyULong = 20;
  41. static float MyFloat = 1.05f;
  42. float *MyFloatRef = &MyFloat;
  43. const double PiSquared = PI * PI;
  44. char *getString()
  45. {
  46. return "This is a literal string";
  47. }
  48. int
  49. getInt()
  50. {
  51. return 42;
  52. }
  53. double
  54. getDouble()
  55. {
  56. return PI;
  57. }
  58. float
  59. getFloat()
  60. {
  61. return (float)PI/2;
  62. }
  63. long getLong()
  64. {
  65. return -321313L;
  66. }
  67. unsigned long
  68. getUnsignedLong()
  69. {
  70. return 23123L;
  71. }
  72. char
  73. getChar()
  74. {
  75. return('A');
  76. }
  77. %}