Re: [SLUG] calling C libs from perl

2003-03-15 Thread Angus Lees
At Fri, 14 Mar 2003 15:31:35 +1030, David Fitch wrote:
 how exactly do you call functions in a C library from a perl script?

The usual way is called XS.  See the perlxstut manpage, which will
also mention the perlguts, perlapi and perlxs manpages.

I'm happy to answer any of the inevitable questions you'll have.

(and I at least would consider such questions perfectly on topic for
slug@ (unless the thread gets really long and specific or something))

-- 
 - Gus
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] calling C libs from perl

2003-03-15 Thread Angus Lees
At Sat, 15 Mar 2003 18:57:56 +1300 (NZDT), Andrew McNaughton wrote:
 On Fri, 14 Mar 2003, David Fitch wrote:
  On Fri, Mar 14, 2003 at 04:14:28PM +1100, Broun, Bevan wrote:
   It would seem that it's worth while buying the Perl CD bookshelf.
 
  ah thanks, got that book already

I found the existing XS manpages fairly good to learn from.  Like
anything else, I had to look at some real world examples before
learning some of the evil tricks.

If you have the choice, I suggest reading the perl5.8 versions of the
manpages, since they are a little more comprehensive (particularly
perlapi). Skip over the bits about unicode and threading, they
(mostly) don't apply to pre-perl5.8.

 Besides using XS directly, you might want to consider using SWIG or h2xs
 to generate the XS code, or perhaps you might want to use Inline.pm to
 inline your C code into your perl.
 
 All of these approaches can be quite simple when you're dealing with
 simple data types at the interface, but get more involved where you need
 to work with perl's data types.

yes, I should have mentioned these.

I've never used either SWIG or Inline.pm - but from what I know of
them:

SWIG is good in that it allows you to write the SWIG wrapper code
once, and use that for all sorts of high-level languagues (eg: guile,
perl, python).  From what I read of it years ago - it did this by
providing a lowest-common-denominator interface.  Fine if you only
have a simple library - bad if you want to provide access to
semi-complicated data structures, or in general provide a more
perlish experience for your users.

Inline.pm is the go if you only have a small set of functions that you
just want to use yourself (not distribute on CPAN or something).  Real
easy to use - good for optimising a particular chunk of code, or
calling a single C function to do something that can't be done by perl
itself; not so good for providing a library interface that will be
directly accessible to outside code.

-- 
 - Gus
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] calling C libs from perl

2003-03-14 Thread Andrew McNaughton
On Fri, 14 Mar 2003, David Fitch wrote:

 Date: Fri, 14 Mar 2003 15:52:34 +1030
 From: David Fitch [EMAIL PROTECTED]
 To: Broun, Bevan [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: [SLUG] calling C libs from perl

 On Fri, Mar 14, 2003 at 04:14:28PM +1100, Broun, Bevan wrote:
  I can tell you it's in chapter 18 of the Advanced Perl Programming
  Oreilly book. There is some documentation at perl.com.au, C and Perl -
  the first two look like putting perl in C and the next calling C from perl.
 
  It would seem that it's worth while buying the Perl CD bookshelf.

 ah thanks, got that book already (but only up to chapt 11 so far)
 so it was under my nose all the time!
 I'd seen that XS stuff but assumed it was for calling perl from
 other languages.

Besides using XS directly, you might want to consider using SWIG or h2xs
to generate the XS code, or perhaps you might want to use Inline.pm to
inline your C code into your perl.

All of these approaches can be quite simple when you're dealing with
simple data types at the interface, but get more involved where you need
to work with perl's data types.

Andrew McNaughton


--
Andrew McNaughton   In Sydney and looking for work
[EMAIL PROTECTED]  http://staff.scoop.co.nz/andrew/cv.doc
Mobile: +61 422 753 792

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


[SLUG] calling C libs from perl

2003-03-13 Thread David Fitch
ok so slightly OT perhaps (it's on linux is my defence!)
and no doubt obvious, but how exactly do you call functions
in a C library from a perl script?  (note: not system calls
or standard C library calls but functions from my own
C library)

I can find plenty of examples the other way around but not
this way.  Either it's so easy/obvious it's not worth
talking about or you can't/don't do it (and I can't believe
that).  So does someone want to enlighten me please...

Dave.
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] calling C libs from perl

2003-03-13 Thread Broun, Bevan
I can tell you it's in chapter 18 of the Advanced Perl Programming
Oreilly book. There is some documentation at perl.com.au, C and Perl -
the first two look like putting perl in C and the next calling C from perl.

It would seem that it's worth while buying the Perl CD bookshelf.

BB

on Fri, Mar 14, 2003 at 03:31:35PM +1030, David Fitch [EMAIL PROTECTED] wrote:
 ok so slightly OT perhaps (it's on linux is my defence!)
 and no doubt obvious, but how exactly do you call functions
 in a C library from a perl script?  (note: not system calls
 or standard C library calls but functions from my own
 C library)
 
 I can find plenty of examples the other way around but not
 this way.  Either it's so easy/obvious it's not worth
 talking about or you can't/don't do it (and I can't believe
 that).  So does someone want to enlighten me please...
 
 Dave.
 -- 
 SLUG - Sydney Linux User's Group - http://slug.org.au/
 More Info: http://lists.slug.org.au/listinfo/slug
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] calling C libs from perl

2003-03-13 Thread David Fitch
On Fri, Mar 14, 2003 at 04:14:28PM +1100, Broun, Bevan wrote:
 I can tell you it's in chapter 18 of the Advanced Perl Programming
 Oreilly book. There is some documentation at perl.com.au, C and Perl -
 the first two look like putting perl in C and the next calling C from perl.
 
 It would seem that it's worth while buying the Perl CD bookshelf.

ah thanks, got that book already (but only up to chapt 11 so far)
so it was under my nose all the time!
I'd seen that XS stuff but assumed it was for calling perl from
other languages.

ta,
Dave.
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug