#vtable #cpp #virtual #viable #api-bindings

macro viable-impl

Interop with C++ MSVC VTables through Rust! If this hasn't been used for a while, you can message me for the name

8 releases

0.2.1 Feb 26, 2022
0.2.0 Feb 26, 2022
0.1.5 Feb 20, 2022

#15 in #vtable

Download history 37/week @ 2024-03-12 11/week @ 2024-03-19 1/week @ 2024-03-26 24/week @ 2024-04-02 1/week @ 2024-04-16 7/week @ 2024-04-23 1/week @ 2024-04-30 16/week @ 2024-05-21 23/week @ 2024-05-28 2/week @ 2024-06-04 48/week @ 2024-06-11 9/week @ 2024-06-18 3/week @ 2024-06-25

62 downloads per month
Used in viable

MIT license

8KB
113 lines

viable 🐍

Interop with C++ MSVC VTables through Rust!

Usage

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.

Dependencies

~1.5MB
~35K SLoC