.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "2020-11-08" "perl v5.32.0" "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 1.34 .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; \& use base qw( Exporter ); \& \& my $ffi = FFI::Platypus\->new; \& # sets constatns 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; \& \& { \& my $ffi = FFI::Platypus\->new( api => 1 ); \& $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 Pisar (ppisar) .PP Mohammad S Anwar (\s-1MANWAR\s0) .PP Håkon Hægland (hakonhagland, \s-1HAKONH\s0) .PP Meredith (merrilymeredith, \s-1MHOWARD\s0) .PP Diab Jerius (\s-1DJERIUS\s0) .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2015,2016,2017,2018,2019,2020 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.