Phoenix.pm: XS/SWIG

Kevin Buettner kev at primenet.com
Wed Dec 1 20:35:33 CST 1999


On Dec 1,  6:37pm, Doug and Julie Miles wrote:

> Has anyone out there used XS or SWIG to glue Perl to C?  I'd put my vote in
> for this as a topic.

I've used XS to embed the perl environment in my favorite editor and
even designed and implemented an API for communicating between the editor
and perl.  See

    http://www.primenet.com/~kev/kevin/software/vile-perl-api.html

for the API details.  (This document is probably a little bit out of
date.) Grab a copy of the vile source code to see how it was done. 
One of the cool things about this document and the source code is that
I embedded the documentation in the source code and then use a perl
one-liner and one of the pod translators to convert it to different
forms.

It's been close to two years since I did any of this though and am a
bit rusty at the moment.  (I.e, I'm probably not the best one to speak
on the subject.)

O'Reilly's "Advanced Perl Programming" does a pretty good job of
covering both XS and SWIG though.  If you're interested in doing this
sort of thing, you'll definitely want to get this book.

If you're contemplating a project like that needs an extension and are
wondering whether to use XS or SWIG...  my feeling is that SWIG is for
wimps.  Writing the XS code is definitely a lot more fun.  (And also a
lot more difficult.) Also, with XS, you'll be able to tailor your
interface so that it is more "perlish".  If you do your interface with
SWIG and fail to provide a wrapper, the stuff you write in perl which
uses the extension library will end up looking a lot like C/C++ code
to do the same thing.

Kevin

-- 
Kevin Buettner
kev at primenet.com, kevinb at cygnus.com



More information about the Phoenix-pm mailing list