3 ExtUtils::XSpp - XS for C++
7 xspp [--typemap=typemap.xsp [--typemap=typemap2.xsp]]
8 [--xsubpp[=/path/to/xsubpp] [--xsubpp-args="xsubpp args"]
13 perl -MExtUtils::XSpp::Cmd -e xspp -- <xspp options and arguments>
17 INCLUDE_COMMAND: $^X -MExtUtils::XSpp::Cmd -e xspp -- <xspp options/arguments>
19 Using C<ExtUtils::XSpp::Cmd> is equivalent to using the C<xspp>
20 command line script, except that there is no guarantee for C<xspp> to
21 be installed in the system PATH.
25 XS++ is just a thin layer over plain XS, hence to use it you
26 are supposed to know, at the very least, C++ and XS.
28 This means that you will need typemaps for B<both> the normal XS
29 pre-processor I<xsubpp> and the XS++ pre-processor I<xspp>.
33 =head2 C<--typemap=/path/to/typemap.xsp>
35 Can be specified multiple times to process additional typemap files
36 before the main XS++ input files. Typemap files are processed the
37 same way as regular XS++ files, except that output code is discarded.
39 =head2 C<--xsubpp[=/path/to/xsubpp]>
41 If specified, XS++ will run F<xsubpp> after processing the XS++ input
42 file. If the path to F<xsubpp> is not specified, F<xspp> expects to
43 find it in the system PATH.
45 =head2 C<--xsubpp-args="extra xsubpp args">
47 Can be used to pass additional command line arguments to F<xsubpp>.
51 There is nothing special about typemap files (i.e. you can put typemaps
52 directly in your .xsp file), but it is handy to have common typemaps in a
53 separate file, to avoid duplication.
55 %typemap{<C++ type>}{simple};
57 Just let XS++ that this is a valid type, the type will be passed
58 unchanged to XS code B<except> that any C<const> qualifiers will be
61 %typemap{<C++ type 1>}{parsed}{%<C++ type 2>%};
63 When C<C++ type 1> is used, replace it with C<C++ type 2> in the
66 %typemap{<C++ reference type>}{reference};
68 Handle C++ references: the XS variable will be declared as a pointer,
69 and it will be explicitly dereferenced in the function call. If it is
70 used in the return value, the function will create B<copy> of the
71 returned value using a copy constructor.
75 Anything that does not look like a XS++ directive or a class
76 declaration is passed verbatim to XS. If you want XS++ to ignore code
77 that looks like a XS++ directive or class declaration, simply surround it with
78 a raw block delimiter like this:
81 XS++ won't interpret this
96 By default XS++ output goes to standard output; to change this, use the
97 C<%file> directive; use C<-> for standard output.
101 %module{Module__Name};
103 Will be used to generate the C<MODULE=Module__Name> XS directives.
107 %name{Perl::Class} class MyClass { ... };
108 %name{Perl::Func} int foo();
110 Specifies the perl name under which the C++ class/function will be
115 See B<TYPEMAPS> above.
119 When you need to pass a string from Perl to an XSUB that
120 takes the C string and its length as arguments,
121 you may have XS++ pass the length of the string automatically.
122 For example, if you declare a method as follows,
124 void PrintLine( char* line, unsigned int %length{line} );
126 you can call the method from Perl like this:
128 $object->PrintLine( $string );
130 This feature is also present in plain XS. See also: L<perlxs>
134 %name{My::Class} class MyClass : public %name{My::Base} MyBase
136 // can be called in Perl as My::Class->new( ... );
138 // My::Class->newMyClass( ... );
139 %name{newMyClass} MyClass( const char* str, int arg );
141 // standard DESTROY method
145 void SetValue( int arg = -1 );
147 %name{SetString} void SetValue( const char* string = NULL );
149 // Supply a C<CODE:> or C<CLEANUP:> block for the XS
150 int MyMethod( int a, int b )
151 %code{% RETVAL = a + b; %}
152 %cleanup{% /* do something */ %};
157 XS++ recognizes both C-style comments C</* ... */> and C++-style
158 comments C<// ...>. Comments are removed from the XS output.
162 Mattia Barbon <mbarbon@cpan.org>
166 This program is free software; you can redistribute it and/or
167 modify it under the same terms as Perl itself.