Skip to content

Commit

Permalink
Fixes for C# bindings (#687)
Browse files Browse the repository at this point in the history
* Fix C# bind gen

* Expose whole seconds and nanoseconds in TimeSpan C API
  • Loading branch information
wooferzfg authored Jun 17, 2023
1 parent 6baad38 commit b3733b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions capi/bind_gen/src/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, class_name: &str) -> R
write!(writer, r#"var result = new {return_type}("#)?;
} else {
write!(writer, "var result = ")?;
if return_type_ll == "UIntPtr" {
if return_type_ll == "UIntPtr" && return_type == "ulong" {
write!(writer, "(ulong)")?;
} else if return_type_ll == "IntPtr" {
} else if return_type_ll == "IntPtr" && return_type == "long" {
write!(writer, "(long)")?;
}
}
Expand All @@ -211,12 +211,12 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, class_name: &str) -> R
"{}",
if name == "this" {
"this.ptr".to_string()
} else if typ.is_custom {
format!("{}.ptr", name.to_lower_camel_case())
} else if ty_name == "UIntPtr" {
format!("(UIntPtr){}", name.to_lower_camel_case())
} else if ty_name == "IntPtr" {
format!("(IntPtr){}", name.to_lower_camel_case())
} else if typ.is_custom {
format!("{}.ptr", name.to_lower_camel_case())
} else {
name.to_lower_camel_case()
}
Expand Down Expand Up @@ -416,7 +416,7 @@ namespace LiveSplitCore
try
{
Marshal.Copy(data, 0, pnt, data.Length);
return Parse(pnt, data.Length, loadFilesPath);
return Parse(pnt, (ulong)data.Length, loadFilesPath);
}
finally
{
Expand Down
14 changes: 14 additions & 0 deletions capi/src/time_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,17 @@ pub unsafe extern "C" fn TimeSpan_parse(text: *const c_char) -> NullableOwnedTim
pub extern "C" fn TimeSpan_total_seconds(this: &TimeSpan) -> f64 {
this.total_seconds()
}

/// Returns the total amount of whole seconds (excluding decimals) this Time
/// Span represents.
#[no_mangle]
pub extern "C" fn TimeSpan_whole_seconds(this: &TimeSpan) -> i64 {
this.to_seconds_and_subsec_nanoseconds().0
}

/// Returns the number of nanoseconds past the last full second that makes up
/// the Time Span.
#[no_mangle]
pub extern "C" fn TimeSpan_subsec_nanoseconds(this: &TimeSpan) -> i32 {
this.to_seconds_and_subsec_nanoseconds().1
}

0 comments on commit b3733b0

Please sign in to comment.