mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
Merge pull request #46 from yamachu/support-reference
Support reference type ( & )
This commit is contained in:
commit
297da130fa
4
csbindgen-tests/src/lib.rs
vendored
4
csbindgen-tests/src/lib.rs
vendored
@ -606,6 +606,9 @@ pub struct CallbackTable {
|
|||||||
pub foobar: extern "C" fn(i: i32) -> i32,
|
pub foobar: extern "C" fn(i: i32) -> i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub extern "C" fn reference_type(_a: &i32, _b: &*mut i32, _c: &[u8; 16], _d: &Context) {}
|
||||||
|
|
||||||
pub struct InternalHiddenContext {
|
pub struct InternalHiddenContext {
|
||||||
pub a: i32
|
pub a: i32
|
||||||
}
|
}
|
||||||
@ -620,6 +623,7 @@ pub unsafe extern "C" fn init_treat_as_empty_struct_context(_out: NonNull<Box<Tr
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn free_treat_as_empty_struct_context(_src: *mut TreatAsEmptyStruct) {}
|
pub unsafe extern "C" fn free_treat_as_empty_struct_context(_src: *mut TreatAsEmptyStruct) {}
|
||||||
|
|
||||||
|
|
||||||
// fn run_physix(){
|
// fn run_physix(){
|
||||||
// unsafe {
|
// unsafe {
|
||||||
// let foundation = physx_create_foundation();
|
// let foundation = physx_create_foundation();
|
||||||
|
@ -495,6 +495,68 @@ fn parse_type(t: &syn::Type) -> RustType {
|
|||||||
type_kind: TypeKind::Function(parameters, ret),
|
type_kind: TypeKind::Function(parameters, ret),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
syn::Type::Reference(t) => {
|
||||||
|
let result = parse_type(&*t.elem);
|
||||||
|
let is_mut = t.mutability.is_some();
|
||||||
|
|
||||||
|
match result {
|
||||||
|
RustType {
|
||||||
|
type_kind: TypeKind::Pointer(pt, _),
|
||||||
|
..
|
||||||
|
} => match pt {
|
||||||
|
PointerType::ConstPointer | PointerType::MutPointer => {
|
||||||
|
return RustType {
|
||||||
|
type_name: result.type_name,
|
||||||
|
type_kind: TypeKind::Pointer(
|
||||||
|
if is_mut {
|
||||||
|
PointerType::MutPointer
|
||||||
|
} else {
|
||||||
|
PointerType::ConstPointer
|
||||||
|
},
|
||||||
|
Box::new(parse_type(&*t.elem)),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
PointerType::ConstPointerPointer | PointerType::MutConstPointerPointer => {
|
||||||
|
return RustType {
|
||||||
|
type_name: result.type_name,
|
||||||
|
type_kind: TypeKind::Pointer(
|
||||||
|
if is_mut {
|
||||||
|
PointerType::MutConstPointerPointer
|
||||||
|
} else {
|
||||||
|
PointerType::ConstPointerPointer
|
||||||
|
},
|
||||||
|
Box::new(parse_type(&*t.elem)),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
PointerType::ConstMutPointerPointer | PointerType::MutPointerPointer => {
|
||||||
|
return RustType {
|
||||||
|
type_name: result.type_name,
|
||||||
|
type_kind: TypeKind::Pointer(
|
||||||
|
if is_mut {
|
||||||
|
PointerType::MutPointerPointer
|
||||||
|
} else {
|
||||||
|
PointerType::ConstMutPointerPointer
|
||||||
|
},
|
||||||
|
Box::new(parse_type(&*t.elem)),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// &*t.elem is not pointer
|
||||||
|
return RustType {
|
||||||
|
type_name: result.type_name,
|
||||||
|
type_kind: TypeKind::Pointer(
|
||||||
|
PointerType::ConstPointer,
|
||||||
|
Box::new(parse_type(&*t.elem)),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
5
dotnet-sandbox/NativeMethods.cs
vendored
5
dotnet-sandbox/NativeMethods.cs
vendored
@ -176,6 +176,10 @@ namespace CsBindgen
|
|||||||
[DllImport(__DllName, EntryPoint = "call_bindgen_lz4", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "call_bindgen_lz4", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void call_bindgen_lz4();
|
public static extern void call_bindgen_lz4();
|
||||||
|
|
||||||
|
|
||||||
|
[DllImport(__DllName, EntryPoint = "reference_type", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void reference_type(int* _a, int** _b, void/* byte[] */* _c, Context* _d);
|
||||||
|
|
||||||
[DllImport(__DllName, EntryPoint = "init_treat_as_empty_struct_context", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "init_treat_as_empty_struct_context", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void init_treat_as_empty_struct_context(TreatAsEmptyStruct** _out);
|
public static extern void init_treat_as_empty_struct_context(TreatAsEmptyStruct** _out);
|
||||||
|
|
||||||
@ -183,6 +187,7 @@ namespace CsBindgen
|
|||||||
public static extern void free_treat_as_empty_struct_context(TreatAsEmptyStruct* _src);
|
public static extern void free_treat_as_empty_struct_context(TreatAsEmptyStruct* _src);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
Loading…
Reference in New Issue
Block a user