<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Hand-written HTML -->
<title>SWIG and MzScheme
</title>
<link rel=
"stylesheet" type=
"text/css" href=
"style.css">
<H1><a name=
"MzScheme"></a>21 SWIG and MzScheme
</H1>
<li><a href=
"#MzScheme_nn2">Creating native MzScheme structures
</a>
This section contains information on SWIG's support of MzScheme.
<H2><a name=
"MzScheme_nn2"></a>21.1 Creating native MzScheme structures
</H2>
/* define a macro for the struct creation */
%define handle_ptr(TYPE,NAME)
%typemap(mzscheme,argout) TYPE *NAME{
Scheme_Object *o = SWIG_NewStructFromPtr($
1, $*
1_mangle);
%typemap(mzscheme,in,numinputs=
0) TYPE *NAME (TYPE temp) {
/* setup the typemaps for the pointer to an output parameter cntrs */
handle_ptr(struct diag_cntrs, cntrs);
Then in scheme, you can use regular struct access procedures like
; suppose a function created a struct foo as
; (define foo (make-diag-cntrs (#x1 #x2 #x3) (make-inspector))
(format
"0x~x" (diag-cntrs-field1 foo))
(format
"0x~x" (diag-cntrs-field2 foo))
That's pretty much it. It works with nested structs as well.