This file contains hidden or 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
// src/bindings.rs | |
use crate::Button; | |
use std::os::raw::c_char; | |
#[repr(C)] | |
pub struct AbstractButtonBinding<T> | |
where T: Button{ | |
pub click: unsafe extern fn(*mut T), | |
pub inner_text: unsafe extern fn(*mut T) -> *const c_char, |
This file contains hidden or 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
// src/engine.rs | |
use std::ffi::c_void; | |
use crate::bindings::engine_factory; | |
pub struct Engine { | |
ptr: *mut c_void | |
} | |
impl Engine { | |
pub fn new() -> Engine { |
This file contains hidden or 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
// bindings.hpp | |
class ButtonBindingConcrete : public AbstractButton { | |
public: | |
explicit ButtonBindingConcrete(AbstractButtonBinding *_binding): binding{_binding} { | |
} | |
// RAII free the pointer on delete | |
~ButtonBindingConcrete() { | |
delete binding; | |
} | |
void click() override { |
This file contains hidden or 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
// bindings.hpp | |
extern "C" { | |
struct AbstractButtonBinding { | |
void (*click)(void *cont); | |
char const *(*inner_text)(void *cont); | |
void *context; | |
}; |
This file contains hidden or 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
// build.rs | |
extern crate cc; | |
fn main() { | |
cc::Build::new() | |
.cpp(true) | |
.include("cpp") | |
.file("cpp/Engine.cpp") | |
.file("cpp/bindings.cpp") |
This file contains hidden or 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
// bindings.hpp | |
extern "C" void register_button(GUI::Engine *engine, AbstractButtonBinding *button) { | |
auto *concrete = new ButtonBindingConcrete(button); | |
engine->registerButton(concrete); | |
}; |
This file contains hidden or 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
#!/bin/bash | |
echo hello world |
OlderNewer