[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FF call to Think C object code?
- To: info-mcl@ministry.cambridge.apple.com
- Subject: Re: FF call to Think C object code?
- From: neves@aristotle.ils.nwu.edu (Neves )
- Date: 26 Oct 1993 16:45:17 GMT
- Newsgroups: comp.lang.lisp.mcl
- Organization: The Institute for the Learning Sciences
- References: <1993Oct26.153933.27987@parc.xerox.com>
Beau Sheil (sheil@adoc.xerox.com) wrote:
: Sorry to ask what is probably a well worn question yet again, but...
: Is it possible to FFcall code that has been compiled using Think C or does it
: HAVE to be MPW object code? (Old) documentation I have seems to suggest that the
: mechanism is MPW object file specific.
I just went through this writing an interface to SpriteWorld.
Cartier's Contribs (available at cambridge.apple.com) has a mechanism
for doing this. You must have the source code to the C program to use
it. You might get away with attaching a code library (which you don't have
source to) to some C interface code but I had problems with that.
The basic idea is to save out the C program as a code resource. Using
the fact that a jump to the start of a code resource is the same as a
call to MAIN() you can have MAIN return the addresses of the routines
you then want to ff-call from Lisp. Cartier has some C macros, a very
nice Lisp interface to ff-call and an example that make all of this
easy.
One word of wisdom -- his C example shows all C functions being passed
Lisp arguments and then having to convert them into C types. Using
that as a guide you would have to change all of your C functions to
call his conversion macros. I found it was possible to use the
regular ff-call types (like :mac, :word and :long) in his Lisp
interface to ff-call to pass values to the C code without having to do any
conversion. The only problem was passing in byte-sized arguments
(like small enumerated types and booleans) which Think C expects (if
fns are defined using prototypes) in the high byte (rather than low
byte as you might expect) of the argument. Conversion there (ash
<num> 8) there is easy.
I had problems calling the Gestalt trap in a multisegmented code
resource so you might have to fit everything in a single segment.
-David