Skip to content
A FFI Wrapper library and header parser!
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
lib Fix tests, as well as test case for ENUM value references Apr 22, 2019
test Fix tests, as well as test case for ENUM value references Apr 22, 2019
.gitignore Some initiual work on parsing Mar 22, 2019
LICENSE First commit for FFIMe wrapper/compiler Feb 17, 2019
README.md Much more work, getting to a stable place Mar 30, 2019
composer.json Break the tests, but fix the bugs. So yeah, need to fix tests :/ Apr 14, 2019
composer.lock Break the tests, but fix the bugs. So yeah, need to fix tests :/ Apr 14, 2019
phpunit.xml.dist A few tests, and fix enum compilation Apr 2, 2019

README.md

FFIMe

This is a wrapper library for PHP 7.4's FFI extension.

You provide it with a shared object, and one or more header files, and it automatically generates the C structures and function signatures for you (just like doing it in C would).

Eventually, this will be more structured to provide a "nicer" interface to use the FFI itself.

Usage:

Currently there are two modes of operation, an "inline" mode:

$libc = (new FFIMe\FFIMe("/lib/x86_64-linux-gnu/libc.so.6"))
        ->include("stdio.h")
        ->build();

$libc->printf("test\n");

And a code generating mode:

(new FFIMe\FFIMe("/lib/x86_64-linux-gnu/libc.so.6"))
        ->include("stdio.h")
        ->include("other.h")
        ->godeGen('full\\classname', 'path/to/file.php');

require 'path/to/file.php';
$libc = new full\classname;
$libc->printf("test\n");

The code generating mode is designed to be used in production, where you'd code generate during a build step and ship with your library.

This should now work for the majority of header files. Looking at some of the code, specifically the compiler, there is quite a bit of hard coding. So I don't expect every file to work out of the box. If you find a header file that doesn't work, just open a bug and we'll take a look.

Check out the examples;

You can’t perform that action at this time.