File: example.i

package info (click to toggle)
swig1.3 1.3.24-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,336 kB
  • ctags: 10,604
  • sloc: cpp: 27,917; ansic: 24,160; yacc: 4,412; python: 4,255; java: 4,156; makefile: 3,735; sh: 3,552; cs: 2,250; ruby: 2,150; lisp: 1,605; tcl: 1,136; perl: 980; php: 879; ml: 825
file content (75 lines) | stat: -rw-r--r-- 1,793 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* File : example.i */
%module example
%include exception.i
%include typemaps.i

extern int    gcd(int x, int y);

%typemap(guile,in) (int argc, char *argv[]) {
  int i;
  SCM *v;
  if (!(SCM_NIMP($input) && SCM_VECTORP($input))) {
    SWIG_exception(SWIG_ValueError, "Expecting a vector");
    return;
  }
  $1 = SCM_LENGTH($input);
  if ($1 == 0) {
    SWIG_exception(SWIG_ValueError, "Vector must contain at least 1 element");
  }
  $2 = (char **) malloc(($1+1)*sizeof(char *));
  v = SCM_VELTS($input);
  for (i = 0; i < $1; i++) {
    if (!(SCM_NIMP(v[i]) && SCM_STRINGP(v[i]))) {
      free($2);	
      SWIG_exception(SWIG_ValueError, "Vector items must be strings");
      return;
    }
    $2[i] = SCM_CHARS(v[i]);
  }
  $2[i] = 0;
}

%typemap(guile,freearg) (int argc, char *argv[]) {
   free($2);
}

extern int gcdmain(int argc, char *argv[]);

%typemap(guile,in) (char *bytes, int len) {
  if (!(SCM_NIMP($input) && SCM_STRINGP($input))) {
    SWIG_exception(SWIG_ValueError, "Expecting a string");
  }
  $1 = SCM_CHARS($input);
  $2 = SCM_LENGTH($input);
}

extern int count(char *bytes, int len, char c);

/* This example shows how to wrap a function that mutates a string */

%typemap(guile,in) (char *str, int len) {
  $1 = gh_scm2newstr($input,&$2);
}

/* Return the mutated string as a new object.  */

%typemap(guile,argout) (char *str, int len) {
  SWIG_APPEND_VALUE(gh_str2scm($1,$2));
  if ($1) scm_must_free($1);
}   

extern void capitalize(char *str, int len);

/* A multi-valued constraint.  Force two arguments to lie
   inside the unit circle */

%typemap(check) (double cx, double cy) {
   double a = $1*$1 + $2*$2;
   if (a > 1.0) {
	SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
   }
}

extern void circle(double cx, double cy);