Skip to content

Conversation

xanathar
Copy link
Contributor

This is useful to support, for example, enum types whose values are significant but whose type is not explicitly used in the functions prototypes.

For example in this code:

/// Returns the id of an opened object, or - if negative - an error code
#[no_mangle]
pub extern "C" fn open_object() -> i64 {
...
}

#[repr(i64)]
pub enum ErrorCode {
     InvalidState = -1,
     BadMood = -2,
     NotAGoodDay = -3,
}

ErrorCode would not be emitted in the generated bindings because it doesn't appear in open_object prototype even if it is a potential return type.

…ed types.

	This is useful to support, for example, enum types whose values
	are significant but whose type is not explicitly used in the
	functions prototypes.
@tvandinther
Copy link

This is a great feature. I've had to create dummy functions utilising these types to have them exported. With this PR, how does the usage change?

@xanathar
Copy link
Contributor Author

xanathar commented Oct 2, 2023

Good point, I forgot to add an example/update the README.

Give me a day or two, I'll send an update.

But essentially its as simple as:

    csbindgen::Builder::default()
        .input_extern_file("myfile.rs");
        .csharp_dll_name("mymodule.dll")
        .csharp_namespace("MyNamespace")
        .always_included_types(["ThisType", "ThisOtherType"])
        .generate_csharp_file("csharp/mybindings.g.cs")
        .unwrap();

@hadashiA
Copy link
Contributor

hadashiA commented Jan 5, 2024

👍 Thanks !

@hadashiA hadashiA merged commit 9fff424 into Cysharp:main Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants