ralfbiedert / interoptopus

The polyglot bindings generator for your library (C#, C, Python, …) 🐙
MIT License
321 stars 28 forks source link

use existing types on C# generated code #79

Open ZhaoXiangXML opened 1 year ago

ZhaoXiangXML commented 1 year ago

For instance in rust we have

#[ffi_type]
#[repr(C)]
pub struct Vec2 {
    pub x: f32,
    pub y: f32,
}

#[ffi_function]
#[no_mangle]
pub extern "C" fn my_function(input: Vec2) -> Vec2 {
    input
}

I'd like to use UnityEngine.Vector2 instead of generated Vec2 type.

        /// Function using the type.
        [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "my_function")]
        public static extern UnityEngine.Vector2 my_function(UnityEngine.Vector2 input);

Is this currently possible?

ralfbiedert commented 1 year ago

This isn't supported out of the box. You might get away by setting name and namespace in ffi_type (see reference project), resolve the namespace to UnityEngine, and avoid emitting it in your Interoptopus C# config. I haven't tried this though. Please post results if you try.