=head1 TITLE Replace XS with the C module as the standard way to extend Perl. =head1 VERSION Maintainer: Brian Ingerson Date: 21 Sep 2000 Mailing List: perl6-language@perl.org Number: 270 Version: 1 Status: Developing =head1 REPLACES RFC 61 - Interfaces for linking C objects into perlsubs =head1 ABSTRACT Extending Perl with XS is too hard. First, there is a hefty learning curve for even simple extensions. Also, the resulting code gets spread out over several files, making it hard to maintain. In the spirit of Perl itself, C makes extending Perl easy for easy things, and possible for harder things. A Perl programmer can write their first C extension in minutes. They can learn more difficult maneuvers as needed. All of the extension code can be in the same file as the Perl script or module. This one-liner is a complete perl extension: perl -e 'print add(2,2);use Inline C=>"int add(int x,int y){return x+y;}"' The first time you run it, you'll notice a pause (compiling). Subsequent runs are lightning fast, as long as the C component isn't modified. =head1 DESCRIPTION C is basically a user friendly abstraction over XS. You feed it a snippet of (C) source and it performs the following steps: 1) Determine if the code snippet has already be compiled. If so, goto 5. 2) Parse function definitions to determine how code should bind to Perl. 3) Generate XS glue code. 4) Build the extension and install it in some known place. 5) DynaLoader the extension. If the extension is a user script or one-liner, the extension will get built and installed in a place that the user has access to. C chooses a reasonable default. The default can easily be over-ridden. If the extension is part of a distributed (ie CPAN) module, the code gets compiled during "make test" and permanently installed in the "installsitearch" during "make install". C is intended to replace 80-90% of the current functionality of XS. Although it does not need to be built over XS, doing so makes C more robust, helps towards backwards compatability, and provides an easy "out" if a project grows to exceed C capabilities. In perl6, something like XS should still exist, but just as a foundation for C. Savvy hackers could defeat C and write glue code themselves, but this would not be the standard. =head1 IMPLEMENTATION All of this is currently functional in C v0.25 (on CPAN now). C seems to work on any machine that has access to the same environment that was used to build Perl itself. Success has been achieved on platforms including MSWin32 and most *nixes. Version 0.25 provides bindings to the following types: C, C, C, C, C. (For anything else the user must pass the argument as a C and do their own type conversion.) There is also support for passing and returning lists. Version 0.30 (not yet released) has no default types. It gets all of its types from XS C files. These files are parsed for their types, which are dumped into the grammar to parse C. Since Perl comes with a generic C file, this is used as the default. It contains all the types listed above and more. This allows XS programmers to use their old typemaps when switching to C. It also allows other modules (like Event.pm) which have an XS API, to publish that API to C seamlessly, using a syntax like "use Inline with => 'Event';" Version 0.30 will also support the following syntax: use Inline; print add(2, 4); __END__ =pod blah blah blah =cut __C__ int add(int x, int y) { return x + y; } If so desired, perl6 might be able to simply recognize the C<__C__> marker, and not require the C at all. The code would look like: print add(2, 4); __C__ int add(int x, int y) { return x + y; } __END__ =pod blah blah blah =cut =head1 REFERENCES RFC 61: Interfaces for linking C objects into perlsubs Inline.pm documentation and tutorial: http://search.cpan.org/doc/INGY/Inline-0.25/lib/Inline.pod http://search.cpan.org/doc/INGY/Inline-0.25/lib/Inline/Config.pod http://search.cpan.org/doc/INGY/Inline-0.25/lib/Inline/C/Tutorial.pod