Created
July 16, 2020 06:07
-
-
Save andyjsbell/16a39a3f502142fa1dc59834daafc6a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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