{"id":17968582,"url":"https://github.com/ghedo/p5-ffi-raw","last_synced_at":"2025-03-25T10:32:22.848Z","repository":{"id":56837173,"uuid":"4062053","full_name":"ghedo/p5-FFI-Raw","owner":"ghedo","description":"Perl bindings to the portable FFI library (libffi)","archived":false,"fork":false,"pushed_at":"2015-01-24T16:18:36.000Z","size":1850,"stargazers_count":26,"open_issues_count":6,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-20T01:05:18.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://metacpan.org/release/FFI-Raw/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghedo.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-18T09:16:46.000Z","updated_at":"2021-10-19T22:18:51.000Z","dependencies_parsed_at":"2022-09-08T01:41:22.599Z","dependency_job_id":null,"html_url":"https://github.com/ghedo/p5-FFI-Raw","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghedo%2Fp5-FFI-Raw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghedo%2Fp5-FFI-Raw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghedo%2Fp5-FFI-Raw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghedo%2Fp5-FFI-Raw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghedo","download_url":"https://codeload.github.com/ghedo/p5-FFI-Raw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245444276,"owners_count":20616350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T14:40:51.597Z","updated_at":"2025-03-25T10:32:21.045Z","avatar_url":"https://github.com/ghedo.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"package FFI::Raw;\n\nuse strict;\nuse warnings;\n\nrequire XSLoader;\nXSLoader::load('FFI::Raw', $FFI::Raw::VERSION);\n\nrequire FFI::Raw::Ptr;\nrequire FFI::Raw::MemPtr;\n\nuse overload\n\t'\u0026{}'  =\u003e \\\u0026coderef,\n\t'bool' =\u003e \\\u0026_bool;\n\nsub _bool {\n\tmy $ffi = shift;\n\treturn $ffi;\n}\n\n=head1 NAME\n\nFFI::Raw - Perl bindings to the portable FFI library (libffi)\n\n=head1 SYNOPSIS\n\n    use FFI::Raw;\n\n    my $cos = FFI::Raw -\u003e new(\n      'libm.so', 'cos',\n      FFI::Raw::double, # return value\n      FFI::Raw::double  # arg #1\n    );\n\n    say $cos -\u003e call(2.0);\n\n=head1 DESCRIPTION\n\nB\u003cFFI::Raw\u003e provides a low-level foreign function interface (FFI) for Perl based\non L\u003clibffi|http://sourceware.org/libffi/\u003e. In essence, it can access and call\nfunctions exported by shared libraries without the need to write C/XS code.\n\nDynamic symbols can be automatically resolved at runtime so that the only\ninformation needed to use B\u003cFFI::Raw\u003e is the name (or path) of the target\nlibrary, the name of the function to call and its signature (though it is also\npossible to pass a function pointer obtained, for example, using L\u003cDynaLoader\u003e).\n\nNote that this module has nothing to do with L\u003cFFI\u003e.\n\n=head1 METHODS\n\n=head2 new( $library, $function, $return_type [, $arg_type ...] )\n\nCreate a new C\u003cFFI::Raw\u003e object. It loads C\u003c$library\u003e, finds the function\nC\u003c$function\u003e with return type C\u003c$return_type\u003e and creates a calling interface.\n\nIf C\u003c$library\u003e is C\u003cundef\u003e then the function is searched in the main program.\n\nThis method also takes a variable number of types, representing the arguments\nof the wanted function.\n\n=head2 new_from_ptr( $function_ptr, $return_type [, $arg_type ...] )\n\nCreate a new C\u003cFFI::Raw\u003e object from the C\u003c$function_ptr\u003e function pointer.\n\nThis method also takes a variable number of types, representing the arguments\nof the wanted function.\n\n=head2 call( [$arg ...] )\n\nExecute the C\u003cFFI::Raw\u003e function. This method also takes a variable number of\narguments, which are passed to the called function. The argument types must\nmatch the types passed to C\u003cnew\u003e (or C\u003cnew_from_ptr\u003e).\n\nThe C\u003cFFI::Raw\u003e object can be used as a CODE reference as well. Dereferencing\nthe object will work just like call():\n\n    $cos -\u003e call(2.0); # normal call() call\n    $cos -\u003e (2.0);     # dereference as CODE ref\n\nThis works because FFI::Raw overloads the C\u003c\u0026{}\u003e operator.\n\n=head2 coderef( )\n\nReturn a code reference of a given C\u003cFFI::Raw\u003e.\n\n=cut\n\nsub coderef {\n\tmy $ffi = shift;\n\treturn sub { $ffi -\u003e call(@_) };\n}\n\n=head1 SUBROUTINES\n\n=head2 memptr( $length )\n\nCreate a L\u003cFFI::Raw::MemPtr\u003e. This is a shortcut for C\u003cFFI::Raw::MemPtr-E\u003cgt\u003enew(...)\u003e.\n\n=cut\n\nsub memptr { FFI::Raw::MemPtr -\u003e new(@_) }\n\n=head2 callback( $coderef, $ret_type [, $arg_type ...] )\n\nCreate a L\u003cFFI::Raw::Callback\u003e. This is a shortcut for C\u003cFFI::Raw::Callback-E\u003cgt\u003enew(...)\u003e.\n\n=cut\n\nsub callback { FFI::Raw::Callback -\u003e new(@_) }\n\n=head1 TYPES\n\n=head2 FFI::Raw::void\n\nReturn a C\u003cFFI::Raw\u003e void type.\n\n=cut\n\nsub void ()  { ord 'v' }\n\n=head2 FFI::Raw::int\n\nReturn a C\u003cFFI::Raw\u003e integer type.\n\n=cut\n\nsub int ()   { ord 'i' }\n\n=head2 FFI::Raw::uint\n\nReturn a C\u003cFFI::Raw\u003e unsigned integer type.\n\n=cut\n\nsub uint ()   { ord 'I' }\n\n=head2 FFI::Raw::short\n\nReturn a C\u003cFFI::Raw\u003e short integer type.\n\n=cut\n\nsub short ()   { ord 'z' }\n\n=head2 FFI::Raw::ushort\n\nReturn a C\u003cFFI::Raw\u003e unsigned short integer type.\n\n=cut\n\nsub ushort ()   { ord 'Z' }\n\n=head2 FFI::Raw::long\n\nReturn a C\u003cFFI::Raw\u003e long integer type.\n\n=cut\n\nsub long ()   { ord 'l' }\n\n=head2 FFI::Raw::ulong\n\nReturn a C\u003cFFI::Raw\u003e unsigned long integer type.\n\n=cut\n\nsub ulong ()   { ord 'L' }\n\n=head2 FFI::Raw::int64\n\nReturn a C\u003cFFI::Raw\u003e 64 bit integer type. This requires L\u003cMath::Int64\u003e to work.\n\n=cut\n\nsub int64 ()   { ord 'x' }\n\n=head2 FFI::Raw::uint64\n\nReturn a C\u003cFFI::Raw\u003e unsigned 64 bit integer type. This requires L\u003cMath::Int64\u003e \nto work.\n\n=cut\n\nsub uint64 ()   { ord 'X' }\n\n=head2 FFI::Raw::char\n\nReturn a C\u003cFFI::Raw\u003e char type.\n\n=cut\n\nsub char ()  { ord 'c' }\n\n=head2 FFI::Raw::uchar\n\nReturn a C\u003cFFI::Raw\u003e unsigned char type.\n\n=cut\n\nsub uchar ()  { ord 'C' }\n\n=head2 FFI::Raw::float\n\nReturn a C\u003cFFI::Raw\u003e float type.\n\n=cut\n\nsub float () { ord 'f' }\n\n=head2 FFI::Raw::double\n\nReturn a C\u003cFFI::Raw\u003e double type.\n\n=cut\n\nsub double () { ord 'd' }\n\n=head2 FFI::Raw::str\n\nReturn a C\u003cFFI::Raw\u003e string type.\n\n=cut\n\nsub str ()   { ord 's' }\n\n=head2 FFI::Raw::ptr\n\nReturn a C\u003cFFI::Raw\u003e pointer type.\n\n=cut\n\nsub ptr ()   { ord 'p' }\n\n=head1 AUTHOR\n\nAlessandro Ghedini \u003calexbio@cpan.org\u003e\n\n=head1 SEE ALSO\n\nL\u003cFFI\u003e, L\u003cCtypes|http://gitorious.org/perl-ctypes\u003e\n\n=head1 LICENSE AND COPYRIGHT\n\nCopyright 2012 Alessandro Ghedini.\n\nThis program is free software; you can redistribute it and/or modify it\nunder the terms of either: the GNU General Public License as published\nby the Free Software Foundation; or the Artistic License.\n\nSee http://dev.perl.org/licenses/ for more information.\n\n=cut\n\n1; # End of FFI::Raw\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghedo%2Fp5-ffi-raw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghedo%2Fp5-ffi-raw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghedo%2Fp5-ffi-raw/lists"}