Kyle R . Burton on Mon, 4 Feb 2002 17:10:29 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Writeing Perl Modules in C


> > 	I am not a big perl guy but I know quite a few of you guys are.  For a 
> > project I need to write a perl module in C/C++.  Do you have any docs or 
> > examples to do this?
> > 
> > 	For the KDE project we are adding perl support for our IPC layer (DCOP) so 
> > you can control and script KDE applications via perl.  So far we support 
> > shell and Python, but perl is sorely missing.  Our current implementation is 
> > using SWIG but the bindings are becoming a real hazard to maintain, when they 
> > are in reality very simple.
> > 
> > 	If any of you guys have experience writing bindings in these languages please 
> > let me know.
> 
> Take a look at the Inline::C and Inline::CPP modules on CPAN.  They
> allow you to embed C and C++ code directly in a Perl script without
> having to use SWIG or XS.  Here's a simple example, taken from the
> Inline::CPP readme file:

I've used the Inline modules, and from a simplicity standpoint, they're 
unbeatable.  I know of no easier way to get up and running quickly with
extensions written in other languages.  On the flip side of that I've found
Inline to be less than desierable from a maintenence standpoint.  Unless
you specify a directory for the compiled code and the temporary code, it
uses PWD/_Inline.  If you run your programs from different places, you end
up with lots of _Inline directoreis.  If you hard code a directory in your
source, it at least gets shared, but if you've got multiple users, or a 
production system where the software might not (or better yet should not)
have write access to the file system, Inline starts to complicate maintenence.

XS code is more cryptic, but if you wrap your code in a module (starting
with h2xs), it's pretty easy to manage.  It's not that hard to write XS
wrappers for the C functions.  The perlguts and perlxs are great resources
for writing C/C++ extensions.

I've taken a shot at writing some Perl extensions in C:

  http://www.bgw.org/tutorials/programming/perl/xsub/xsub.php

Also, if you're into Perl, there is a local users group:

  http://phl.pm.org/

They might be able to offer more suggestions/advice.

Kyle

-- 

------------------------------------------------------------------------------
Wisdom and Compassion are inseparable.
        -- Christmas Humphreys
mortis@voicenet.com                            http://www.voicenet.com/~mortis
------------------------------------------------------------------------------

______________________________________________________________________
Philadelphia Linux Users Group       -      http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug