FFI-Platypus-Lang-Zig
view release on metacpan or search on metacpan
lib/FFI/Platypus/Lang/Zig.pm view on Meta::CPAN
package FFI::Platypus::Lang::Zig;
use strict;
use warnings;
use feature qw( state );
use File::ShareDir::Dist qw( dist_share );
use 5.020;
# ABSTRACT: Documentation and tools for using Platypus with the Zig programming language
our $VERSION = '0.02'; # VERSION
sub native_type_map {
state $map = do {
my %map = (
u8 => 'uint8',
u16 => 'uint16',
u32 => 'uint32',
u64 => 'uint64',
# u128 unsupported by Platypus
i8 => 'sint8',
i16 => 'sint16',
i32 => 'sint32',
i64 => 'sint64',
# i128 unsupported by Platypus
# f16 unsupported by Platypus
f32 => 'float',
f64 => 'double',
f128 => 'longdouble',
anyopaque => 'opaque',
);
# computed at installtime:
# isize, usize, c_short c_ushort c_int c_uint
# c_longlong c_ulonglong c_longdouble bool
my $dir = dist_share( 'FFI-Platypus-Lang-Zig' );
my $map2 = require "$dir/types.pl";
%map = (%map, %$map2);
\%map;
};
$map;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
FFI::Platypus::Lang::Zig - Documentation and tools for using Platypus with the Zig programming language
=head1 VERSION
version 0.02
=head1 SYNOPSIS
Zig:
pub export fn add(a: i32, b: i32) i32 {
return a + b;
}
Perl:
use FFI::Platypus 2.00;
use FFI::CheckLib qw( find_lib_or_die );
use File::Basename qw( dirname );
my $ffi = FFI::Platypus->new( api => 2, lang => 'Zig' );
$ffi->lib(
find_lib_or_die(
lib => 'add',
libpath => [dirname __FILE__],
systempath => [],
)
);
$ffi->attach( add => ['i32','i32'] => 'i32' );
print add(1,2), "\n"; # prints 3
=head1 DESCRIPTION
This module provides native Zig types for FFI::Platypus in order to
reduce cognitive load and concentrate on Zig and forget about C types.
This document also covers using Platypus with Zig, and includes a
number of examples.
Note that in addition to using pre-compiled Zig libraries, you can
( run in 1.850 second using v1.01-cache-2.11-cpan-54e63673c56 )