好的,我正在努力实现以下目标:
我一直在玩它。我走了很远,但还没有到那里。
C位:
#include <dlfcn.h>
#include <stdio.h>
void *global_ctx;
void c_function(void* ctx) {
printf("Called c_function\n");
global_ctx = ctx;
}
int main(void) {
void *thing = dlopen("thing/target/debug/libthing.dylib", RTLD_NOW | RTLD_GLOBAL);
if (!thing) {
printf("error: %s\n", dlerror());
return 1;
}
void (*rust_function)(void) = dlsym(thing, "rust_function");
void (*rust_cb)(void*) = dlsym(thing, "rust_cb");
printf("rust_function = %p\n", rust_function);
rust_function();
rust_cb(global_ctx);
}
Run Code Online (Sandbox Code Playgroud)
锈点:
extern crate libc;
pub trait Foo {
fn callback(&self);
}
extern …Run Code Online (Sandbox Code Playgroud)