1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <!-- Hand-written HTML -->
5 <title>SWIG and MzScheme</title>
6 <link rel="stylesheet" type="text/css" href="style.css">
9 <body bgcolor="#ffffff">
11 <H1><a name="MzScheme"></a>25 SWIG and MzScheme</H1>
13 <div class="sectiontoc">
15 <li><a href="#MzScheme_nn2">Creating native MzScheme structures</a>
23 This section contains information on SWIG's support of MzScheme.
25 <H2><a name="MzScheme_nn2"></a>25.1 Creating native MzScheme structures</H2>
29 Example interface file:
34 /* define a macro for the struct creation */
35 %define handle_ptr(TYPE,NAME)
36 %typemap(argout) TYPE *NAME{
37 Scheme_Object *o = SWIG_NewStructFromPtr($1, $*1_mangle);
41 %typemap(in,numinputs=0) TYPE *NAME (TYPE temp) {
46 /* setup the typemaps for the pointer to an output parameter cntrs */
47 handle_ptr(struct diag_cntrs, cntrs);
52 Then in scheme, you can use regular struct access procedures like
57 ; suppose a function created a struct foo as
58 ; (define foo (make-diag-cntrs (#x1 #x2 #x3) (make-inspector))
60 (format "0x~x" (diag-cntrs-field1 foo))
61 (format "0x~x" (diag-cntrs-field2 foo))
67 That's pretty much it. It works with nested structs as well.