Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ex/attach.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env perl
use 5.36.3;
use lib qw(lib);

use Raylib::FFI ':all';
use Raylib::Color;

Raylib::FFI::attach( rlTranslatef => [ ( 'float' ) x 3 ] );
Raylib::FFI::attach( [ rlRotatef => 'rotate' ] => [ ( 'float' ) x 4 ] );
Raylib::FFI->import( qw( rlTranslatef rotate ) );

InitWindow( 800, 600, "Testing!" );
SetTargetFPS(60);

my $r = 0;
while ( !WindowShouldClose() ) {
ClearBackground( Raylib::Color::BLACK );
BeginDrawing();
rlTranslatef( 400, 300 );
rotate( $r += 3, 0, 0, -1 );
DrawText( "Weeee!", 0, 0, 40, Raylib::Color::WHITE );
EndDrawing();
}

31 changes: 31 additions & 0 deletions lib/Raylib/FFI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,14 @@ for my $func ( keys %functions ) {
# export all the functions lexically
our @EXPORT_OK = grep { __PACKAGE__->can($_) } keys %functions;
our %EXPORT_TAGS = (all => \@EXPORT_OK);

sub attach {
my $name = shift;
$ffi->attach( $name => @_ );
my $perl_name = ref $name eq 'ARRAY' ? $name->[1] : $name;
push @EXPORT_OK, $perl_name;
}

1;

__END__
Expand Down Expand Up @@ -3205,6 +3213,29 @@ Set pan for audio stream (0.5 is center)

Default size for new audio streams

=head1 Ad-hoc binding

Binding to the most commonly used Raylib functions is provided by this module.
However, Raylib's API includes hundreds of functions not explicitly defined
here which may prove useful, e.g. those in the
L<rlgl module|https://github.com/raysan5/raylib/blob/master/src/rlgl.h>.

=head2 attach

A function called attach is provided (though not exported) which allows you to
bind additional Raylib functions at run-time. These functions may then be
imported to your namespace.

This works identically to L<FFI::Platypus/attach>:

use Raylib::FFI ':all';

Raylib::FFI::attach( rlTranslatef => [ ( 'float' ) x 3 ] );
Raylib::FFI->import( qw( rlTranslatef ) );

# use rlTranslatef() here


=head1 KNOWN ISSUES

Also, this module was put together very quickly, and it's not very well tested.
Expand Down
Loading