.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "FFI::Platypus::Constant 3pm" .TH FFI::Platypus::Constant 3pm 2024-01-10 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME FFI::Platypus::Constant \- Define constants in C space for Perl .SH VERSION .IX Header "VERSION" version 2.08 .SH SYNOPSIS .IX Header "SYNOPSIS" \&\f(CW\*(C`ffi/foo.c\*(C'\fR: .PP .Vb 1 \& #include \& \& 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 */ \& } .Ve .PP \&\f(CW\*(C`lib/Foo.pm\*(C'\fR: .PP .Vb 1 \& package Foo; \& \& use strict; \& use warnings; \& use FFI::Platypus 2.00; \& use Exporter qw( import ); \& \& my $ffi = FFI::Platypus\->new( api => 2 ); \& # sets constants Foo::FOO and ABC::DEF from C \& $ffi\->bundle; \& \& 1; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" The Platypus bundle interface (see FFI::Platypus::Bundle) has an entry point \&\f(CW\*(C`ffi_pl_bundle_constant\*(C'\fR that lets you define constants in Perl space from C. .PP .Vb 1 \& void ffi_pl_bundle_constant(const char *package, ffi_platypus_constant_t *c); .Ve .PP The first argument \f(CW\*(C`package\*(C'\fR is the name of the Perl package. The second argument \&\f(CW\*(C`c\*(C'\fR 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 \f(CW\*(C`::\*(C'\fR 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 \f(CW\*(C`bundle\*(C'\fR. .IP set_str 4 .IX Item "set_str" .Vb 1 \& c\->set_str(name, value); .Ve .Sp Sets a string constant. .IP set_sint 4 .IX Item "set_sint" .Vb 1 \& c\->set_sint(name, value); .Ve .Sp Sets a 64\-bit signed integer constant. .IP set_uint 4 .IX Item "set_uint" .Vb 1 \& c\->set_uint(name, value); .Ve .Sp Sets a 64\-bit unsigned integer constant. .IP set_double 4 .IX Item "set_double" .Vb 1 \& c\->set_double(name, value); .Ve .Sp Sets a double precision floating point constant. .SS Example .IX Subsection "Example" Suppose you have a header file \f(CW\*(C`myheader.h\*(C'\fR: .PP .Vb 2 \& #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 .Ve .PP You can define these constants from C: .PP .Vb 2 \& #include \& #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); \& } .Ve .PP Your Perl code doesn't have to do anything when calling bundle: .PP .Vb 1 \& package Const; \& \& use strict; \& use warnings; \& use FFI::Platypus 2.00; \& \& { \& my $ffi = FFI::Platypus\->new( api => 2 ); \& $ffi\->bundle; \& } \& \& 1; .Ve .SH AUTHOR .IX Header "AUTHOR" Author: Graham Ollis .PP Contributors: .PP Bakkiaraj Murugesan (bakkiaraj) .PP Dylan Cali (calid) .PP pipcet .PP Zaki Mughal (zmughal) .PP Fitz Elliott (felliott) .PP Vickenty Fesunov (vyf) .PP Gregor Herrmann (gregoa) .PP Shlomi Fish (shlomif) .PP Damyan Ivanov .PP Ilya Pavlov (Ilya33) .PP Petr Písař (ppisar) .PP Mohammad S Anwar (MANWAR) .PP Håkon Hægland (hakonhagland, HAKONH) .PP Meredith (merrilymeredith, MHOWARD) .PP Diab Jerius (DJERIUS) .PP Eric Brine (IKEGAMI) .PP szTheory .PP José Joaquín Atria (JJATRIA) .PP Pete Houston (openstrike, HOUSTON) .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2015\-2022 by Graham Ollis. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.