| 1 | package SDL2::loadso 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use experimental 'signatures'; | ||
| 4 | # | ||
| 5 | use SDL2::stdinc; | ||
| 6 | use SDL2::error; | ||
| 7 | # | ||
| 8 | attach loadso => { | ||
| 9 | SDL_LoadObject => [ ['string'], 'opaque' ], | ||
| 10 | SDL_LoadFunction => [ | ||
| 11 | [ 'opaque', 'string' ], | ||
| 12 | 'opaque', | ||
| 13 | sub ( $inner, $handle, $name, $params = (), $retval = () ) { | ||
| 14 | my $fn = $inner->( $handle, $name ); | ||
| 15 | $fn && $params ? SDL2::Utils::ffi->function( $fn, $params, $retval ) : $fn; | ||
| 16 | } | ||
| 17 | ], | ||
| 18 | SDL_UnloadObject => [ ['opaque'] ] | ||
| 19 | }; | ||
| 20 | |||
| 21 | =encoding utf-8 | ||
| 22 | |||
| 23 | =head1 NAME | ||
| 24 | |||
| 25 | SDL2::loadso - Dynamically Load a Shared Object | ||
| 26 | |||
| 27 | =head1 SYNOPSIS | ||
| 28 | |||
| 29 | use SDL2 qw[:loadso]; | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | System dependent library loading routines. | ||
| 34 | |||
| 35 | Some things to keep in mind: | ||
| 36 | |||
| 37 | =over | ||
| 38 | |||
| 39 | =item | ||
| 40 | |||
| 41 | These functions only work on C function names. Other languages may have name | ||
| 42 | mangling and intrinsic language support that varies from compiler to compiler. | ||
| 43 | |||
| 44 | =item | ||
| 45 | |||
| 46 | Make sure you declare your function pointers with the same calling convention | ||
| 47 | as the actual library function. Your code will crash mysteriously if you do | ||
| 48 | not do this. | ||
| 49 | |||
| 50 | =item | ||
| 51 | |||
| 52 | Avoid namespace collisions. If you load a symbol from the library, it is not | ||
| 53 | defined whether or not it goes into the global symbol namespace for the | ||
| 54 | application. If it does and it conflicts with symbols in your code or other | ||
| 55 | shared libraries, you will not get the results you expect. :) | ||
| 56 | |||
| 57 | =back | ||
| 58 | |||
| 59 | =head1 Functions | ||
| 60 | |||
| 61 | These functions may be imported by name or with the C<:loadso> tag. | ||
| 62 | |||
| 63 | =head2 C<SDL_LoadObject( ... )> | ||
| 64 | |||
| 65 | Dynamically load a shared object. | ||
| 66 | |||
| 67 | Expected parameters include: | ||
| 68 | |||
| 69 | =over | ||
| 70 | |||
| 71 | =item C<sofile> - a system-dependent name of the object file | ||
| 72 | |||
| 73 | =back | ||
| 74 | |||
| 75 | Returns an opaque pointer to the object handle or C<undef> if there was an | ||
| 76 | error; call C<SDL_GetError( )> for more information. | ||
| 77 | |||
| 78 | =head2 C<SDL_LoadFunction( ... )> | ||
| 79 | |||
| 80 | Look up the address of the named function in a shared object. | ||
| 81 | |||
| 82 | This function pointer is no longer valid after calling L<< C<SDL_UnloadObject( | ||
| 83 | ... )>|/C<SDL_UnloadObject( ... )> >>. | ||
| 84 | |||
| 85 | This function can only look up C function names. Other languages may have name | ||
| 86 | mangling and intrinsic language support that varies from compiler to compiler. | ||
| 87 | |||
| 88 | Make sure you declare your function pointers with the same calling convention | ||
| 89 | as the actual library function. Your code will crash mysteriously if you do not | ||
| 90 | do this. | ||
| 91 | |||
| 92 | If the requested function doesn't exist, C<undef> is returned. | ||
| 93 | |||
| 94 | Expected parameters include: | ||
| 95 | |||
| 96 | =over | ||
| 97 | |||
| 98 | =item C<handle> - a valid shared object handle returned by L<< C<SDL_LoadObject( ... )>|/C<SDL_LoadObject( ... )> >> | ||
| 99 | |||
| 100 | =item C<name> - the name of the function to look up | ||
| 101 | |||
| 102 | =item C<arguments> - optional L<FFI::Platypus>-friendly argument list | ||
| 103 | |||
| 104 | =item C<retval> - optional L<FFI::Platypus>-friendly return value | ||
| 105 | |||
| 106 | =back | ||
| 107 | |||
| 108 | Returns a pointer to the function or C<undef> if there was an error; call | ||
| 109 | C<SDL_GetError( )> for more information. | ||
| 110 | |||
| 111 | Note: We break from the upstream API by automatically wrapping the function | ||
| 112 | pointer if provided with an argument list. | ||
| 113 | |||
| 114 | =head2 C<SDL_UnloadObject( ... )> | ||
| 115 | |||
| 116 | Unload a shared object from memory. | ||
| 117 | |||
| 118 | Expected parameters include: | ||
| 119 | |||
| 120 | =over | ||
| 121 | |||
| 122 | =item C<handle> - a valid shared object handle returned by L<< C<SDL_LoadObject( ... )>|/C<SDL_LoadObject( ... )> >> | ||
| 123 | |||
| 124 | =back | ||
| 125 | |||
| 126 | =head1 LICENSE | ||
| 127 | |||
| 128 | Copyright (C) Sanko Robinson. | ||
| 129 | |||
| 130 | This library is free software; you can redistribute it and/or modify it under | ||
| 131 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 132 | conditions may apply to data transmitted through this module. | ||
| 133 | |||
| 134 | =head1 AUTHOR | ||
| 135 | |||
| 136 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 137 | |||
| 138 | =begin stopwords | ||
| 139 | |||
| 140 | =end stopwords | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | }; | ||
| 145 | 1; |