NAME

Inline::C2XS - create an XS file from an Inline C file.

DESCRIPTION

Don't feed an actual Inline::C script to this module - it won't
be able to parse it. It is capable of parsing correctly only
that C code that is suitable for inclusion in an Inline::C
script.

For example, here is a simple Inline::C script:

 use warnings;
 use Inline C => <<'EOC';
 #include <stdio.h>

 void greet() {
     printf("Hello world\n");
 }
 EOC

 greet();
 __END__

The C file that Inline::C2XS needs to find would contain only that code
that's between the opening 'EOC' and the closing 'EOC' - namely:

 #include <stdio.h>

 void greet() {
     printf("Hello world\n");
 }

Inline::C2XS looks for the file in ./src directory - expecting that the
filename will be the same as what appears after the final '::' in the
module name (with a '.c' extension). ie if the module is called
My::Next::Mod it looks for a file ./src/Mod.c, and creates a file
named Mod.xs (in the cwd). Also created in the cwd, is the file
'INLINE.h' - but only if that file is needed.

The created XS file, when packaged with the '.pm' file, an
appropriate 'Makefile.PL', and 'INLINE.h' (if it's needed),
can be used to build the module in the usual way - without
any dependence upon the Inline C module.

SYNOPSIS

use Inline::C2XS qw(c2xs);

my $module_name = 'MY::XS_MOD';
my $package_name = 'MY::XS_MOD';

# Create XS_MOD.xs from ./src/XS_MOD.c. Also creates INLINE.h, if
# that file is needed. 'XS_MOD.c' must be in a format that works
# with the Inline::C module and must be in the ./src folder.
c2xs($module_name, $package_name);

BUGS

Assumes that the function prototypes/declarations are written on 
the one line - ie a .c file containing this works fine:

unsigned long some_func(int a, double b, SV * c)
  {
  // code
  }

And this also works fine:

unsigned long some_func(int a, double b, SV * c) {
  // code
  }

But this won't work (though it's valid C code, and works with
Inline::C):

unsigned long some_func(int a,
                        double b,
                        SV * c)
  {
  // code
  }

Also, safest to keep comments to separate lines, or to the end of a
line. This won't be correctly parsed (by either Inline::C or Inline::C2XS):

/* A comment */ void another_func(char * something) // Another comment
   {
   printf("%s\n", something);
   }

But there's no problem with:

/* A comment */
void another_func(char * something) { // Another comment
   printf("%s\n", something);
   }

And there's no problem with:

void another_func(char * something) { /* A comment
continuation of comment */ 
   printf("%s\n", something);
   }

Same applies to single line comments (//). 

Probably other bugs, too - patches/rewrites welcome.
Send to sisyphus at cpan dot org

COPYRIGHT

Copyright Sisyphus. You can do whatever you want with this code.
It comes without any guarantee or warranty.