YAPC day 2: Embedding C in Perl

jdavidb on 2002-06-27T19:55:44

Embedding C in Perl by Chris Brooks. I've never done XS before, so I'll be happy to see a bit.

Chris said by the time he finished his talk draft, he'd basically rewritten perlxstut.

target C subroutine: the one you want to use

Matt, Chris used AxPoint to put his presentation together and couldn't figure out how to put in angle brackets. Maybe a FAQ candidate?

XS source code file: glue code

Namespace resolution:

XS gives you 2 API functions to install xsubs as Perl subs: newXS() and newXSproto(). Takes

  • name to assign function
  • pointer to xsub
  • name of C source code file (just for debugging)

newXS() can't be called from your program. Instead you use DynaLoader, which calls newXS() for you. You subclass DynaLoader and call bootstrap(), a wrapper around some internal functions that eventually call newXS().

XS syntax. Use MODULE and PACKAGE keywords. Before that line, everything is C (or POD).

MODULE = Mytest2 PACKAGE = Mytest2

Perl scalars and things are not just C variables.

I'm being inspired to sit down and learn XS. Tonight. Somebody stop me.

www.organiccodefarm.com/xs.pdf is the presentation slides. Worth reading, along with perlxstut. PerlMonth 1999 articles.