wrap and rename ALL the types

This commit is contained in:
Vinzenz Schroeter 2024-09-05 21:15:53 +02:00
parent b9fc06117e
commit 051dbfabea
18 changed files with 577 additions and 480 deletions

View file

@ -14,9 +14,9 @@ namespace ServicePoint.BindGen
{
const string __DllName = "servicepoint_binding_c";
public const nuint TILE_SIZE = 8;
public const nuint TILE_WIDTH = 56;
public const nuint TILE_HEIGHT = 20;
public const nuint SP_TILE_SIZE = 8;
public const nuint SP_TILE_WIDTH = 56;
public const nuint SP_TILE_HEIGHT = 20;
/// <summary>
@ -629,7 +629,7 @@ namespace ServicePoint.BindGen
///
/// The caller has to make sure that:
///
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
/// - the returned `SPCommand` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`.
/// </summary>
[DllImport(__DllName, EntryPoint = "sp_command_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
@ -637,19 +637,19 @@ namespace ServicePoint.BindGen
/// <summary>
/// Allocates a new `Command::CharBrightness` instance.
/// The passed `ByteGrid` gets consumed.
/// The passed `SPBrightnessGrid` gets consumed.
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `byte_grid` points to a valid instance of `ByteGrid`
/// - `byte_grid` is not used concurrently or after this call
/// - `grid` points to a valid instance of `SPBrightnessGrid`
/// - `grid` is not used concurrently or after this call
/// - the returned `Command` instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_dealloc`.
/// </summary>
[DllImport(__DllName, EntryPoint = "sp_command_char_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp_command_char_brightness(nuint x, nuint y, BrightnessGrid* byte_grid);
public static extern Command* sp_command_char_brightness(nuint x, nuint y, BrightnessGrid* grid);
/// <summary>
/// Allocates a new `Command::BitmapLinear` instance.
@ -1040,6 +1040,21 @@ namespace ServicePoint.BindGen
[DllImport(__DllName, EntryPoint = "sp_packet_try_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Packet* sp_packet_try_load(byte* data, nuint length);
/// <summary>
/// Clones a `Packet`.
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - `this` points to a valid `Packet`
/// - `this` is not written to concurrently
/// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_packet_dealloc`.
/// </summary>
[DllImport(__DllName, EntryPoint = "sp_packet_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Packet* sp_packet_clone(Packet* @this);
/// <summary>
/// Deallocates a `Packet`.
///
@ -1076,13 +1091,6 @@ namespace ServicePoint.BindGen
{
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct ByteSlice
{
public byte* start;
public nuint length;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Connection
{
@ -1093,6 +1101,13 @@ namespace ServicePoint.BindGen
{
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct ByteSlice
{
public byte* start;
public nuint length;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Packet
{

View file

@ -13,23 +13,18 @@ fn main() {
.input_extern_file("../servicepoint_binding_c/src/lib.rs")
.input_extern_file("../servicepoint_binding_c/src/c_slice.rs")
.input_extern_file("../servicepoint_binding_c/src/packet.rs")
.input_extern_file("../servicepoint/src/command.rs")
.input_extern_file("../servicepoint/src/connection.rs")
.input_extern_file("../servicepoint/src/pixel_grid.rs")
.input_extern_file("../servicepoint/src/lib.rs")
.input_extern_file("../servicepoint/src/packet.rs")
.input_extern_file("../servicepoint/src/compression_code.rs")
.input_extern_file("../servicepoint_binding_c/src/constants.rs")
.csharp_dll_name("servicepoint_binding_c")
.csharp_namespace("ServicePoint.BindGen")
.csharp_use_nint_types(true)
.csharp_class_accessibility("public")
.csharp_generate_const_filter(|_| true)
.csharp_type_rename(move |name| {
if name.len() > 1
&& name.starts_with("C")
&& name.chars().nth(1).unwrap().is_uppercase()
if name.len() > 2
&& name.starts_with("SP")
&& name.chars().nth(2).unwrap().is_uppercase()
{
name[1..].to_string()
name[2..].to_string()
} else {
name
}