PHP to rust FFI example
This commit is contained in:
9
php-to-rust/src/ffi.php
Normal file
9
php-to-rust/src/ffi.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$libExtension = (PHP_OS_FAMILY == "Darwin" ? 'dylib' : 'so');
|
||||
|
||||
$ffi = FFI::cdef(
|
||||
"int32_t double_input(int32_t input);",
|
||||
"target/debug/libdouble_input.$libExtension");
|
||||
var_dump($ffi->double_input(3));
|
||||
?>
|
||||
5
php-to-rust/src/lib.rs
Normal file
5
php-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#[no_mangle]
|
||||
pub extern fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user