File: example.i

package info (click to toggle)
swig1.3 1.3.36-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 27,060 kB
  • ctags: 13,774
  • sloc: cpp: 40,816; ansic: 27,565; python: 9,069; java: 6,432; makefile: 5,065; yacc: 4,916; cs: 4,551; sh: 4,071; ruby: 3,760; perl: 3,562; lisp: 1,993; tcl: 1,266; php: 1,026; ml: 708
file content (36 lines) | stat: -rwxr-xr-x 1,033 bytes parent folder | download | duplicates (10)
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
%module example

%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_ary, int i, VALUE key, VALUE val) {
  Check_Type($input, T_HASH);
  $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
  $2 = NULL;
  $3 = NULL;
  if ($1 > 0) {
    $2 = (char **) malloc($1*sizeof(char *));
    $3 = (int *) malloc($1*sizeof(int));
    keys_ary = rb_funcall($input, rb_intern("keys"), 0, NULL);
    for (i = 0; i < $1; i++) {
      key = rb_ary_entry(keys_ary, i);
      val = rb_hash_aref($input, key);
      Check_Type(key, T_STRING);
      Check_Type(val, T_FIXNUM);
      $2[i] = STR2CSTR(key);
      $3[i] = NUM2INT(val);
    }
  }
}

%typemap(freearg) (int nattributes, const char **names, const int *values) {
  free((void *) $2);
  free((void *) $3);
}

%inline %{
void setVitalStats(const char *person, int nattributes, const char **names, const int *values) {
  int i;
  printf("Name: %s\n", person);
  for (i = 0; i < nattributes; i++) {
    printf("  %s => %d\n", names[i], values[i]);
  }
}
%}