Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
2 | <!-- Hand-written HTML --> | |
3 | <html> | |
4 | <head> | |
5 | <title>SWIG and MzScheme</title> | |
6 | <link rel="stylesheet" type="text/css" href="style.css"> | |
7 | </head> | |
8 | ||
9 | <body bgcolor="#ffffff"> | |
10 | ||
11 | <H1><a name="MzScheme"></a>21 SWIG and MzScheme</H1> | |
12 | <!-- INDEX --> | |
13 | <div class="sectiontoc"> | |
14 | <ul> | |
15 | <li><a href="#MzScheme_nn2">Creating native MzScheme structures</a> | |
16 | </ul> | |
17 | </div> | |
18 | <!-- INDEX --> | |
19 | ||
20 | ||
21 | ||
22 | <p> | |
23 | This section contains information on SWIG's support of MzScheme. | |
24 | ||
25 | <H2><a name="MzScheme_nn2"></a>21.1 Creating native MzScheme structures</H2> | |
26 | ||
27 | ||
28 | <p> | |
29 | Example interface file: | |
30 | </p> | |
31 | ||
32 | <div class="code"> | |
33 | <pre> | |
34 | /* define a macro for the struct creation */ | |
35 | %define handle_ptr(TYPE,NAME) | |
36 | %typemap(mzscheme,argout) TYPE *NAME{ | |
37 | Scheme_Object *o = SWIG_NewStructFromPtr($1, $*1_mangle); | |
38 | SWIG_APPEND_VALUE(o); | |
39 | } | |
40 | ||
41 | %typemap(mzscheme,in,numinputs=0) TYPE *NAME (TYPE temp) { | |
42 | $1 = &temp; | |
43 | } | |
44 | %enddef | |
45 | ||
46 | /* setup the typemaps for the pointer to an output parameter cntrs */ | |
47 | handle_ptr(struct diag_cntrs, cntrs); | |
48 | </pre> | |
49 | </div> | |
50 | ||
51 | <p> | |
52 | Then in scheme, you can use regular struct access procedures like | |
53 | </p> | |
54 | ||
55 | <div class="code"> | |
56 | <pre> | |
57 | ; suppose a function created a struct foo as | |
58 | ; (define foo (make-diag-cntrs (#x1 #x2 #x3) (make-inspector)) | |
59 | ; Then you can do | |
60 | (format "0x~x" (diag-cntrs-field1 foo)) | |
61 | (format "0x~x" (diag-cntrs-field2 foo)) | |
62 | ;etc... | |
63 | </pre> | |
64 | </div> | |
65 | ||
66 | <p> | |
67 | That's pretty much it. It works with nested structs as well. | |
68 | </p> | |
69 | ||
70 | </body> | |
71 | </html> |