mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
support tuple struct
This commit is contained in:
parent
168936d9ff
commit
32af3f29e0
10
csbindgen-tests/src/lib.rs
vendored
10
csbindgen-tests/src/lib.rs
vendored
@ -124,6 +124,16 @@ pub extern "C" fn comment_one() {
|
||||
pub extern "C" fn long_jpn_comment() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
pub struct my_int_vec3(i32,i32,i32);
|
||||
|
||||
pub extern "C" fn use_vec3(_v3: my_int_vec3) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
pub struct NfcCard {
|
||||
pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{alias_map::AliasMap, builder::BindgenOptions, field_map::FieldMap, type_meta::*};
|
||||
use regex::Regex;
|
||||
use std::{collections::HashSet, fmt::format};
|
||||
use std::{collections::HashSet};
|
||||
use syn::{ForeignItem, Item, Pat, ReturnType};
|
||||
|
||||
enum FnItem {
|
||||
@ -156,7 +156,15 @@ pub fn collect_struct(ast: &syn::File, result: &mut Vec<RustStruct>) {
|
||||
fields,
|
||||
is_union: false,
|
||||
});
|
||||
};
|
||||
} else if let syn::Fields::Unnamed(f) = &t.fields {
|
||||
let struct_name = t.ident.to_string();
|
||||
let fields = collect_fields_unnamed(f);
|
||||
result.push(RustStruct {
|
||||
struct_name,
|
||||
fields,
|
||||
is_union: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,6 +185,23 @@ fn collect_fields(fields: &syn::FieldsNamed) -> Vec<FieldMember> {
|
||||
result
|
||||
}
|
||||
|
||||
fn collect_fields_unnamed(fields: &syn::FieldsUnnamed) -> Vec<FieldMember> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
let mut i = 0;
|
||||
for field in &fields.unnamed {
|
||||
i += 1;
|
||||
let name = format!("Item{i}");
|
||||
let t = parse_type(&field.ty);
|
||||
result.push(FieldMember {
|
||||
name: name,
|
||||
rust_type: t,
|
||||
});
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
||||
for item in ast.items.iter() {
|
||||
if let Item::Enum(t) = item {
|
||||
@ -208,7 +233,7 @@ pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
||||
enum_name,
|
||||
fields,
|
||||
repr,
|
||||
is_flags: false
|
||||
is_flags: false,
|
||||
});
|
||||
} else if let Item::Macro(t) = item {
|
||||
let last_segment = t.mac.path.segments.last().unwrap();
|
||||
@ -238,7 +263,16 @@ pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
||||
.map(|x| {
|
||||
(
|
||||
x.get(1).unwrap().as_str().to_string(),
|
||||
Some(x.get(2).unwrap().as_str().to_string().replace("Self :: ", "").replace(" . bits", "").trim().to_string()),
|
||||
Some(
|
||||
x.get(2)
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.to_string()
|
||||
.replace("Self :: ", "")
|
||||
.replace(" . bits", "")
|
||||
.trim()
|
||||
.to_string(),
|
||||
),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@ -247,7 +281,7 @@ pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
||||
enum_name,
|
||||
fields,
|
||||
repr,
|
||||
is_flags: true
|
||||
is_flags: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
11
dotnet-sandbox/NativeMethods.cs
vendored
11
dotnet-sandbox/NativeMethods.cs
vendored
@ -24,6 +24,9 @@ namespace CsBindgen
|
||||
[DllImport(__DllName, EntryPoint = "long_jpn_comment", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void long_jpn_comment();
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "use_vec3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void use_vec3(my_int_vec3 _v3);
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "other_2", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
public static extern void other_2(NfcCard _hoge);
|
||||
|
||||
@ -157,6 +160,14 @@ namespace CsBindgen
|
||||
public fixed byte png_name[5];
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct my_int_vec3
|
||||
{
|
||||
public int Item1;
|
||||
public int Item2;
|
||||
public int Item3;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe partial struct NfcCard
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user