cxx
cxx copied to clipboard
Support passing function pointers across the FFI
i.e. function parameters with the type fn(...) -> ...
.
#[cxx::bridge]
mod ffi {
extern "Rust" {
fn f(arg: u8, callback: fn(u8));
}
}
fn f(arg: u8, callback: fn(u8)) {
callback(256 - arg);
}
Passing function pointers from Rust to C++ was implemented in #79 + #85. It remains to implement passing the reverse direction.
@dtolnay What's the plan for solving this? You are going to use std::function? Can I help with the implementation?
@dtolnay What's the plan for solving this? You are going to use std::function? Can I help with the implementation?
Do you have any progress about this?
I want this feature, and as cxx not support it, so I have to use
#[no_mangle]
extern "C" fn register_callback(extern "C" fn(c_int)) {
todo!()
}
to register function pointer(with specific function signature) on a static memory, and in Rust call the callback
Can I do something for support this feature? @dtolnay and this design is ok?
Here's a pattern to use std::function
with current cxx facilities.
Here's a pattern to use
std::function
with current cxx facilities.I used this, but it does not support dynamic libraries, can you give me a hand, tks!!
Undefined symbols for architecture arm64: "_cn$rongcloud$cxxbridge1$MyFunction$call", referenced from: imlib::ffi::MyFunction::call::hb153764149e230b4 in imlib.4dg0tx688zy81d57.rcgu.o
https://github.com/ios-yifan/rust-std.git
@adetaylor