The Platypus bundle interface (see FFI::Platypus::Bundle) has an entry point "ffi_pl_bundle_constant"
that lets you define constants in Perl space from C.
void ffi_pl_bundle_constant(const char *package, ffi_platypus_constant_t *c);
The first argument "package" is the name of the Perl package. The second argument "c" is a struct with
function pointers that lets you define constants of different types. The first argument for each
function is the name of the constant and the second is the value. If "::" is included in the constant
name then it will be defined in that package space. If it isn't then the constant will be defined in
whichever package called "bundle".
set_str
c->set_str(name, value);
Sets a string constant.
set_sint
c->set_sint(name, value);
Sets a 64-bit signed integer constant.
set_uint
c->set_uint(name, value);
Sets a 64-bit unsigned integer constant.
set_double
c->set_double(name, value);
Sets a double precision floating point constant.
Example
Suppose you have a header file "myheader.h":
#ifndef MYHEADER_H
#define MYHEADER_H
#define MYVERSION_STRING "1.2.3"
#define MYVERSION_MAJOR 1
#define MYVERSION_MINOR 2
#define MYVERSION_PATCH 3
enum {
MYBAD = -1,
MYOK = 1
};
#define MYPI 3.14
#endif
You can define these constants from C:
#include <ffi_platypus_bundle.h>
#include "myheader.h"
void ffi_pl_bundle_constant(const char *package, ffi_platypus_constant_t *c)
{
c->set_str("MYVERSION_STRING", MYVERSION_STRING);
c->set_uint("MYVERSION_MAJOR", MYVERSION_MAJOR);
c->set_uint("MYVERSION_MINOR", MYVERSION_MINOR);
c->set_uint("MYVERSION_PATCH", MYVERSION_PATCH);
c->set_sint("MYBAD", MYBAD);
c->set_sint("MYOK", MYOK);
c->set_double("MYPI", MYPI);
}
Your Perl code doesn't have to do anything when calling bundle:
package Const;
use strict;
use warnings;
use FFI::Platypus 2.00;
{
my $ffi = FFI::Platypus->new( api => 2 );
$ffi->bundle;
}
1;