summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2011-02-05 14:30:36 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2011-02-05 14:30:36 +0000
commit1f46e842122735c61bc22b8ca0ea6f194471ecd7 (patch)
tree49530d54e328ffb27b5eb3699036532fcc6bfa8a
parenta5837dd7e61007d7a4849ef9fd59506bdac42bda (diff)
downloadswig-1f46e842122735c61bc22b8ca0ea6f194471ecd7.tar.gz
SF #2942899 Add user supplied documentation to help getting started with MzScheme. Update chapter name to MzScheme/Racket accounting for the rename of MzScheme to Racket.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12436 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--CHANGES.current4
-rw-r--r--Doc/Manual/Mzscheme.html117
2 files changed, 115 insertions, 6 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 4a1c3f8e9..729a04217 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,10 @@ Version 2.0.2 (in progress)
2011-02-05: wsfulton
+ [MzScheme] SF #2942899 Add user supplied documentation to help getting started with MzScheme.
+ Update chapter name to MzScheme/Racket accounting for the rename of MzScheme to Racket.
+
+2011-02-05: wsfulton
[C#] SF #3085906 - Possible fix running test-suite on Mac OSX.
2011-02-05: wsfulton
diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html
index 257e58b95..eb6b00dd0 100644
--- a/Doc/Manual/Mzscheme.html
+++ b/Doc/Manual/Mzscheme.html
@@ -2,17 +2,19 @@
<!-- Hand-written HTML -->
<html>
<head>
-<title>SWIG and MzScheme</title>
+<title>SWIG and MzScheme/Racket</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#ffffff">
-<H1><a name="Mzscheme"></a>27 SWIG and MzScheme</H1>
+<H1><a name="Mzscheme"></a>27 SWIG and MzScheme/Racket</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
-<li><a href="#MzScheme_nn2">Creating native MzScheme structures</a>
+<li><a href="#MzScheme_nn2">Creating native structures</a>
+<li><a href="#MzScheme_simple">Simple example</a>
+<li><a href="#MzScheme_c_documentation">External documentation</a>
</ul>
</div>
<!-- INDEX -->
@@ -20,9 +22,9 @@
<p>
-This section contains information on SWIG's support of MzScheme.
+This section contains information on SWIG's support of Racket, formally known as MzScheme.
-<H2><a name="MzScheme_nn2"></a>27.1 Creating native MzScheme structures</H2>
+<H2><a name="MzScheme_nn2"></a>27.1 Creating native structures</H2>
<p>
@@ -63,8 +65,111 @@ Then in scheme, you can use regular struct access procedures like
</pre>
</div>
+<H2><a name="MzScheme_simple"></a>27.2 Simple example</H2>
+
+
+<p>
+A few examples are available in the Examples/mzscheme directory.
+The code and log of a session using SWIG below should help getting started.
+</p>
+
+<p>
+C header file:
+</p>
+
+<div class="code">
+<pre>
+// example.h
+int fact(int n);
+</pre>
+</div>
+
+<p>
+C source code:
+</p>
+
+<div class="code">
+<pre>
+// File: example.c
+#include "example.h"
+
+int fact(int n) {
+ if (n &lt; 0) { /* This should probably return an error, but this is simpler */
+ return 0;
+ }
+ if (n == 0) {
+ return 1;
+ }
+ else {
+ /* testing for overflow would be a good idea here */
+ return n * fact(n-1);
+ }
+}
+</pre>
+</div>
+
+<p>
+SWIG interface file:
+</p>
+
+<div class="code">
+<pre>
+/* File: example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+int fact(int n);
+</pre>
+</div>
+
+<p>
+The session below using the above files is on an OS X machine, but the points to be made are more general. On OS X, libtool is the tool which creates libraries, which are named .dylib, rather than .so on other unixes, or .dll on Windows.
+</p>
+
+<div class="shell">
+<pre>
+% swig -mzscheme -declaremodule example.i
+% gcc -c -m32 -o example.o example.c # force 32-bit object file (mzscheme is 32-bit only)
+% libtool -dynamic -o libexample.dylib example.o # make it into a library
+% ls # what've we got so far?
+example.c example.o
+example.h example_wrap.c
+example.i libexample.dylib*
+% mzc --cgc --cc example_wrap.c # compile the wrapping code
+% LDFLAGS="-L. -lexample" mzc --ld example_wrap.dylib example_wrap.o # ...and link it
+% mzscheme -e '(path-&gt;string (build-path "compiled" "native" (system-library-subpath)))'
+"compiled/native/i386-macosx/3m"
+% mkdir -p compiled/native/i386-macosx/3m # move the extension library to a magic place
+% mv example_wrap.dylib compiled/native/i386-macosx/3m/example_ss.dylib
+% mzscheme
+Welcome to MzScheme v4.2.4 [3m], Copyright (c) 2004-2010 PLT Scheme Inc.
+&gt; (require "example.ss")
+&gt; (fact 5)
+120
+&gt; ^D
+% echo 'It works!'
+</pre>
+</div>
+
+
+<p>
+Some points of interest:
+</p>
+<ul>
+ <li> This is on a 64-bit machine, so we have to include the -m32 option when building the object file
+ <li> If you want to declare a scheme module (and you probably do), it's important that you include the -declaremodule option to swig (if you miss this out, it'll appear to work, but fail later).
+ <li> Use mzc to compile and then link the wrapped code. You'll probably need to adjust the link flags to refer to the library you're wrapping (you can either do this with an LDFLAGS declaration, as here, or with multiple ++ldf options to mzc).
+ <li> Create the directory with path (build-path "compiled" "native" (system-library-subpath)) and move the freshly-generated .dylib to there, changing its name to module-name_ss.dylib. After that, you can REQUIRE the new module with (require "module-name.ss").
+</ul>
+
+<H2><a name="MzScheme_c_documentation"></a>27.3 External documentation</H2>
+
+
<p>
-That's pretty much it. It works with nested structs as well.
+See the <a href="http://docs.racket-lang.org/inside/index.html">C API</a> for more description of using the mechanism for adding extensions. The main documentation is <a href="http://docs.racket-lang.org/">here</a>.
</p>
</body>