Skip to content

Commit b3733b0

Browse files
authored
Fixes for C# bindings (#687)
* Fix C# bind gen * Expose whole seconds and nanoseconds in TimeSpan C API
1 parent 6baad38 commit b3733b0

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

capi/bind_gen/src/csharp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, class_name: &str) -> R
191191
write!(writer, r#"var result = new {return_type}("#)?;
192192
} else {
193193
write!(writer, "var result = ")?;
194-
if return_type_ll == "UIntPtr" {
194+
if return_type_ll == "UIntPtr" && return_type == "ulong" {
195195
write!(writer, "(ulong)")?;
196-
} else if return_type_ll == "IntPtr" {
196+
} else if return_type_ll == "IntPtr" && return_type == "long" {
197197
write!(writer, "(long)")?;
198198
}
199199
}
@@ -211,12 +211,12 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, class_name: &str) -> R
211211
"{}",
212212
if name == "this" {
213213
"this.ptr".to_string()
214+
} else if typ.is_custom {
215+
format!("{}.ptr", name.to_lower_camel_case())
214216
} else if ty_name == "UIntPtr" {
215217
format!("(UIntPtr){}", name.to_lower_camel_case())
216218
} else if ty_name == "IntPtr" {
217219
format!("(IntPtr){}", name.to_lower_camel_case())
218-
} else if typ.is_custom {
219-
format!("{}.ptr", name.to_lower_camel_case())
220220
} else {
221221
name.to_lower_camel_case()
222222
}
@@ -416,7 +416,7 @@ namespace LiveSplitCore
416416
try
417417
{
418418
Marshal.Copy(data, 0, pnt, data.Length);
419-
return Parse(pnt, data.Length, loadFilesPath);
419+
return Parse(pnt, (ulong)data.Length, loadFilesPath);
420420
}
421421
finally
422422
{

capi/src/time_span.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,17 @@ pub unsafe extern "C" fn TimeSpan_parse(text: *const c_char) -> NullableOwnedTim
4242
pub extern "C" fn TimeSpan_total_seconds(this: &TimeSpan) -> f64 {
4343
this.total_seconds()
4444
}
45+
46+
/// Returns the total amount of whole seconds (excluding decimals) this Time
47+
/// Span represents.
48+
#[no_mangle]
49+
pub extern "C" fn TimeSpan_whole_seconds(this: &TimeSpan) -> i64 {
50+
this.to_seconds_and_subsec_nanoseconds().0
51+
}
52+
53+
/// Returns the number of nanoseconds past the last full second that makes up
54+
/// the Time Span.
55+
#[no_mangle]
56+
pub extern "C" fn TimeSpan_subsec_nanoseconds(this: &TimeSpan) -> i32 {
57+
this.to_seconds_and_subsec_nanoseconds().1
58+
}

0 commit comments

Comments
 (0)