Crates.io | viable-impl |
lib.rs | viable-impl |
version | 0.2.1 |
source | src |
created_at | 2022-02-02 07:32:12.043649 |
updated_at | 2022-02-26 03:24:35.87282 |
description | Interop with C++ MSVC VTables through Rust! If this hasn't been used for a while, you can message me for the name. |
homepage | |
repository | https://github.com/Vurv78/viable |
max_upload_size | |
id | 525581 |
size | 8,564 |
viable
🐍Interop with C++ MSVC VTables through Rust!
use std::os::raw::c_int;
use viable::vtable;
extern "C" {
fn getMath(i: c_int) -> *mut Math;
}
#[vtable]
struct Math {
internal: c_int,
add: extern "C" fn(a: c_int, b: c_int) -> c_int,
#[offset(1)] // Completely optional
add2: extern "C" fn(a: c_int, b: c_int) -> c_int,
}
pub fn main() {
let iface = unsafe { getMath(10) };
let iface = unsafe { iface.as_mut().unwrap() };
// Yep. Even this works
assert_eq!( iface.internal, 10 );
assert_eq!( iface.add2(5, 5), 5 + 5 + 10 );
}
See viable-tests/src/basic.cpp for C++ source.