diff --git a/CHANGES.current b/CHANGES.current index 4a1c3f8e9..729a04217 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -6,6 +6,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. 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 @@
--This section contains information on SWIG's support of MzScheme. +This section contains information on SWIG's support of Racket, formally known as MzScheme. -
@@ -63,8 +65,111 @@ Then in scheme, you can use regular struct access procedures like +
-That's pretty much it. It works with nested structs as well. +A few examples are available in the Examples/mzscheme directory. +The code and log of a session using SWIG below should help getting started. +
+ ++C header file: +
+ ++// example.h +int fact(int n); ++
+C source code: +
+ +
+// File: example.c
+#include "example.h"
+
+int fact(int n) {
+ if (n < 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);
+ }
+}
+
++SWIG interface file: +
+ +
+/* File: example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+int fact(int n);
+
++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. +
+ ++% 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->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. +> (require "example.ss") +> (fact 5) +120 +> ^D +% echo 'It works!' ++
+Some points of interest: +
++See the C API for more description of using the mechanism for adding extensions. The main documentation is here.