Created
July 15, 2020 18:57
-
-
Save andyjsbell/bca6a5317802adf24acffdd76166ea84 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 method() { | |
std::cout << "method called" << std::endl; | |
methodImpl(); | |
} | |
protected: | |
virtual void methodImpl() { | |
std::cout << "methodImpl called" << std::endl; | |
} | |
}; | |
}} | |
cpp!{{ | |
class TestImpl : public Test { | |
protected: | |
virtual void methodImpl() override { | |
std::cout << "methodImpl override called" << std::endl; | |
rust!(My_Rust_MethodImpl [] { | |
println!("hey there!"); | |
}); | |
} | |
}; | |
}} | |
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->method(); | |
}) | |
} | |
} | |
} | |
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