Полезная информация

Advanced Perl Programming

Advanced Perl ProgrammingSearch this book
Previous: 18.4 XS FeaturesChapter 18
Extending Perl:A First Course
Next: 18.6 A Detour into Fractals

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.


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 FeaturesAdvanced Perl ProgrammingNext: 18.6 A Detour into Fractals
18.4 XS FeaturesBook Index18.6 A Detour into Fractals