Skip to content

Instantly share code, notes, and snippets.

@andyjsbell
Created July 16, 2020 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyjsbell/16a39a3f502142fa1dc59834daafc6a2 to your computer and use it in GitHub Desktop.
Save andyjsbell/16a39a3f502142fa1dc59834daafc6a2 to your computer and use it in GitHub Desktop.
use cpp::cpp;
use cpp::cpp_class;
cpp!{{
#include <iostream>
class Test {
public:
void fireEvent() {
std::cout << "fireEvent called" << std::endl;
onEvent(100, 200);
}
protected:
virtual void onEvent(int, int) {
std::cout << "onEvent called" << std::endl;
}
};
}}
cpp!{{
class TestImpl : public Test {
protected:
virtual void onEvent(int a, int b) override {
rust!(My_Rust_MethodImpl [this : TestImpl as "TestImpl*", a : u32 as "int", b : u32 as "int"] {
this.on_event(a, b);
});
}
};
}}
cpp_class!(pub unsafe struct TestImpl as "TestImpl");
impl TestImpl {
fn new() -> Self {
unsafe { cpp!([] -> TestImpl as "TestImpl" { return TestImpl(); }) }
}
fn run(&self) {
unsafe {
cpp!([self as "TestImpl*"] {
self->fireEvent();
})
}
}
fn on_event(&self, a: u32, b: u32) {
println!("event - {} {}", a, b)
}
}
fn main() {
let t = TestImpl::new();
t.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment