#vtable #table #virtual #interact #index #pointers

vtables

Interact with C++ virtual method tables from Rust

1 unstable release

0.1.0 Jul 22, 2021

#12 in #vtable

Download history 15/week @ 2024-09-21 11/week @ 2024-09-28 1/week @ 2024-10-05 11/week @ 2024-11-23 29/week @ 2024-11-30 27/week @ 2024-12-07

67 downloads per month
Used in 2 crates

GPL-3.0 license

14KB

vtables

Interact with C++ virtual method tables from Rust

Usage

Clone both this and vtables_derive and add the following to your Cargo.toml:

[dependencies]
vtables = "0.1"
vtables_derive = "0.1"

You can then use methods from the virtual method table like this:

use vtables::VTable;
use vtables_derive::VTable;
use vtables_derive::has_vtable;
use vtables_derive::virtual_index;

#[has_vtable]
#[derive(VTable, Debug)]
pub struct EngineClient {
}

#[allow(non_snake_case)]
impl EngineClient {
    #[virtual_index(5)]
    pub fn GetScreenSize(&self, width: *mut i32, height: *mut i32) {}
    
    #[virtual_index(26)]
    pub fn IsInGame(&self) -> bool {}

    #[virtual_index(108)]
    pub fn ExecuteClientCmd(&self, command: *const c_char) {}

    #[virtual_index(113)]
    pub fn ClientCmd_Unrestricted(&self, command: *const c_char) {}
}

A field containing the virtual method table pointer will automatically be added to your structure. Support for multiple inheritance is untested.

No runtime deps