home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


18.5 Degrees of Freedom

Before we conclude the essential part of this chapter, let us quickly recap all the places where you can plug in code to help XS and SWIG produce a smooth interface (for the script programmer):

Perl module

So far, the Perl module produced by these tools has been used only to bootstrap the C code, but there's no reason why it shouldn't have some custom subroutines too. The XS example presented earlier, in the "Modifying Parameters" section, could easily have been implemented in Perl space.

Typemaps

Supply snippets of code to convert between Perl and C data types.

Wrapper code in the interface files

The CODE and PPCODE directives allow you to insert a variety of custom translation tasks. In SWIG, you can inline custom C code as follows:

    %module FunMath
    %inline %{
        int factorial(int n){return (n == 1) ? 1 : n *(n -1)};
    %}


Previous: 18.4 XS Features Advanced Perl Programming Next: 18.6 A Detour into Fractals
18.4 XS Features Book Index 18.6 A Detour into Fractals

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.