2. Text
Every time you open a pipe to a program to do something
that Perl already knows how to do, God kills a kitten.
- @pplu_io
!
Check CPAN to save kittens.
6. XS is an interface description file format
used to create an extension interface
between Perl and C code (or a C library)
which one wishes to use with Perl.
-perlxs 1:1
7. “Hooking Perl to C using XS requires you to write a
shell.pm module to bootstrap an object file that has
been compiled from C code, which was in turn
generated by xsubpp from a.xs source file
containing pseudo-C annotated with an XS interface
description.”
–Brian D. Foy, “Perl Best Practices”
8. “Hooking Perl to C using XS requires you
to write a shell.pm module
to bootstrap an object file
that has been compiled from C code,
which was in turn
generated by xsubpp
from a.xs source file
containing pseudo-C
annotated with an XS interface description.”
–Brian D. Foy, “Perl Best Practices”
9. “If that sounds horribly complicated,
then you have achieved an accurate
understanding of the use of xsubpp.”
–Brian D. Foy, “Perl Best Practices”
15. “SWIG is an interface compiler that connects
programs written in C and C++ with scripting
languages such as Perl, Python, Ruby, and Tcl.”
– http://www.swig.org/exec.html
17. SWIG
Open Source (GPL)
Created in 1995 by Dave Beazley
Support for a couple dozen languages by 2014
http://www.swig.org/
18. Supported Languages
Tcl
Python
Perl
Java
Ruby
PHP
Ocaml
Pike
C#
Scheme
Modula-3
Lua
Common Lisp
R
Octave
Go
D
Javascript
http://www.swig.org/compat.html#SupportedLanguages
19. Interface definition
/* File : example.i */
!
%module example
!
%inline %{
extern int gcd(int x, int y);
extern double Foo;
%}
20. C file
/* File : example.c */
!
/* A global variable */
double Foo = 3.0;
!
/* Compute the greatest common divisor of positive
integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}