| Walt Mankowski on Mon, 4 Feb 2002 16:30:20 +0100 |
|
On Mon, Feb 04, 2002 at 10:09:32AM -0500, ian reinhart geiser wrote:
> 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:
--
Inline::CPP -- Write Perl subroutines and classes in C++.
Inline::CPP lets you write Perl subroutines and classes in C++. You
don't have to learn XS or SWIG, you can just put code right "inline"
in your source.
Example:
use Inline CPP => <<'END';
class JAxH {
public:
JAxH(char *x);
SV* data();
private:
SV *dat;
};
JAxH::JAxH(char *x) { dat = newSVpvf("Just Another %s Hacker", x); }
SV* JAxH::data() { return dat; }
END
print JAxH->new('Inline')->data(), "\n";
When run, this complete program prints:
Just Another Inline Hacker.
--
Walter C. Mankowski
Senior Software Engineer Myxa Corporation
phone: (610) 234-2626 fax: (610) 234-2640
email: walt@myxa.com http://www.myxa.com
Attachment:
pgpnqWt6YPEfV.pgp
|
|