Module interoptopus_backend_csharp::overloads [−][src]
Expand description
Overloads provide additional methods for .NET and Unity.
We recommend to always add the DotNet
writer (unless you want to handle overloads yourself), even when targeting Unity.
The Unity
writer should only be added when Unity support is needed, and will require a Config::use_unsafe
setting of Unsafe::UnsafeKeyword
or higher.
Background
Normally the C# backend only emits simple signatures. These mostly contain primitive types, structs, IntPtr
, and all of the above mixed with ref
our out
:
public static extern uint my_function(Sliceu32 slice);
Overload writers provide additional convenience methods. For example the DotNet
writer might add:
public static uint my_function(uint[] slice) { ... }
While the Unity
writer could add:
public static uint my_function(NativeArray<uint> slice) { ... }
Example
Overloads are passed to a Generator
like this:
#[test]
fn bindings_csharp() -> Result<(), Error> {
use interoptopus_backend_csharp::{Generator, Config};
use interoptopus_backend_csharp::overloads::{Unity, DotNet};
let config = Config::default();
Generator::new(config, example_library_ffi::my_inventory())
.add_overload_writer(Unity::new())
.add_overload_writer(DotNet::new())
.write_file("bindings/csharp/Interop.cs")?;
Ok(())
}
Structs
Highly recommended, provides most convenience methods.
Provides Unity overloads, make sure to use Unsafe::UnsafeKeyword
or higher.