PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 2ms 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
 1%module r_legacy
 2%inline %{
 3typedef char *String;
 4
 5typedef struct {
 6  int i;
 7  double d;
 8  char *str;
 9  String s;
10} Obj;
11
12Obj *getObject(int i, double d);
13
14#include <string.h>
15
16Obj *
17getObject(int i, double d)
18{
19
20  const char *test_string = "a test string";
21  Obj *obj;
22  obj = (Obj *) calloc(1, sizeof(Obj));
23
24  obj->i = i;
25  obj->d = d;
26  /* allocate one extra byte for the null */
27  obj->str = (char *)malloc(strlen(test_string) + 1);
28  strcpy(obj->str, test_string);
29
30  return(obj);
31}
32%}
33
34char *getString();
35int getInt();
36double getDouble();
37float getFloat();
38long getLong();
39unsigned long getUnsignedLong();
40char getChar();
41
42extern unsigned long MyULong;
43
44extern const double PiSquared;
45
46#if 0
47extern float *MyFloatRef;
48#endif
49
50%inline %{
51#define PI 3.14159265358979
52unsigned long MyULong = 20;
53
54static float MyFloat = 1.05f;
55float *MyFloatRef = &MyFloat;
56
57const double PiSquared = PI * PI;
58
59char *getString()
60{
61  return "This is a literal string";
62}
63
64int 
65getInt()
66{
67 return 42;
68}
69
70double 
71getDouble()
72{
73  return PI;
74}
75
76float 
77getFloat()
78{
79  return (float)PI/2;
80}
81
82long getLong()
83{
84  return -321313L;
85}
86
87unsigned long 
88getUnsignedLong()
89{
90  return 23123L;
91}
92
93char
94getChar()
95{
96  return('A');
97}
98%}