Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Latest commit

 

History

History
37 lines (28 loc) · 918 Bytes

File metadata and controls

37 lines (28 loc) · 918 Bytes

Archived

I don't plan on working on this library as it adds very minimal levels of abstractions and the syntax is too opinionated.

If anyone wants to claim the crates.io library slot, get in contact with me at 0x76757276 on Discord, or if that doesn't work email me from my GitHub email.

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.