GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
FFI::Platypus::Constant(3) User Contributed Perl Documentation FFI::Platypus::Constant(3)

FFI::Platypus::Constant - Define constants in C space for Perl

version 1.56

"ffi/foo.c":

 #include <ffi_platypus_bundle.h>
 
 void
 ffi_pl_bundle_constant(const char *package, ffi_platypus_constant_t *c)
 {
   c->set_str("FOO", "BAR");       /* sets $package::FOO to "BAR" */
   c->set_str("ABC::DEF", "GHI");  /* sets ABC::DEF to GHI        */
 }

"lib/Foo.pm":

 package Foo;
 
 use strict;
 use warnings;
 use FFI::Platypus 1.00;
 use Exporter qw( import );
 
 my $ffi = FFI::Platypus->new( api => 1 );
 # sets constants Foo::FOO and ABC::DEF from C
 $ffi->bundle;
 
 1;

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.

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 1.00;
 
 {
   my $ffi = FFI::Platypus->new( api => 1 );
   $ffi->bundle;
 }
 
 1;

Author: Graham Ollis <plicease@cpan.org>

Contributors:

Bakkiaraj Murugesan (bakkiaraj)

Dylan Cali (calid)

pipcet

Zaki Mughal (zmughal)

Fitz Elliott (felliott)

Vickenty Fesunov (vyf)

Gregor Herrmann (gregoa)

Shlomi Fish (shlomif)

Damyan Ivanov

Ilya Pavlov (Ilya33)

Petr Písař (ppisar)

Mohammad S Anwar (MANWAR)

Håkon Hægland (hakonhagland, HAKONH)

Meredith (merrilymeredith, MHOWARD)

Diab Jerius (DJERIUS)

Eric Brine (IKEGAMI)

szTheory

José Joaquín Atria (JJATRIA)

Pete Houston (openstrike, HOUSTON)

This software is copyright (c) 2015,2016,2017,2018,2019,2020 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2021-10-28 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.