ExtUtils::Constant - generate XS code to import C header constants |
ExtUtils::Constant - generate XS code to import C header constants
use ExtUtils::Constant qw (WriteConstants); WriteConstants( NAME => 'Foo', NAMES => [qw(FOO BAR BAZ)], ); # Generates wrapper code to make the values of the constants FOO BAR BAZ # available to perl
ExtUtils::Constant facilitates generating C and XS wrapper code to allow
perl modules to AUTOLOAD constants defined in C library header files.
It is principally used by the h2xs
utility, on which this code is based.
It doesn't contain the routines to scan header files to extract these
constants.
Generally one only needs to call the WriteConstants
function, and then
#include "const-c.inc"
in the C section of Foo.xs
INCLUDE: const-xs.inc
in the XS section of Foo.xs
.
For greater flexibility use constant_types()
, C_constant
and
XS_constant
, with which WriteConstants
is implemented.
Currently this module understands the following types. h2xs may only know
a subset. The sizes of the numeric types are chosen by the Configure
script at compile time.
double
, possibly long double
strlen
PL_sv_yes
) The value is not needed (and ignored).
PL_sv_no
) The value is not needed (and ignored).
undef
. The value of the macro is not needed.
#define
definitions for the
constants used internally between the generated C and XS functions.
C_constant
, and usually named constant
.
TYPES should be given either as a comma separated list of types that the
C subroutine constant
will generate or as a reference to a hash. It should
be the same list of types as C_constant
was given.
[Otherwise XS_constant
and C_constant
may have different ideas about
the number of parameters passed to the C function constant
]
You can call the perl visible subroutine something other than constant
if
you give the parameter SUBNAME. The C subroutine it calls defaults to
the name of the perl visible subroutine, unless you give the parameter
C_SUBNAME.
constant()
routine doesn't recognise.
A function to generate perl code for Makefile.PL that will regenerate
the constant subroutines. Parameters are named as passed to WriteConstants
,
with the addition of INDENT
to specify the number of leading spaces
(default 2).
Currently only INDENT
, NAME
, DEFAULT_TYPE
, NAMES
, C_FILE
and
XS_FILE
are recognised.
#include
and INCLUDE
in the C and XS sections respectively of your module's XS
code. You probably want to do this in your Makefile.PL
, so that you can
easily edit the list of constants without touching the rest of your module.
The attributes supported are
IV
is assumed.
const-c.inc
. The -
in the name ensures that the file can't be
mistaken for anything related to a legitimate perl package name, and
not naming the file .c
avoids having to override Makefile.PL's
.xs
to .c
rules.
const-xs.inc
.
constant
.
_
and the name
length appended, so constants with 10 character names would be in
constant_10
with the default XS_SUBNAME.
Nicholas Clark <nick@ccl4.org> based on the code in h2xs
by Larry Wall and
others
ExtUtils::Constant - generate XS code to import C header constants |