Fixes for FFI, refactor FFI Error to be easier to implement
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::ffi::ffi_handle::{FFIHandle, FromFFIHandle};
|
||||
use crate::ffi::{ffi_handle_arc_dyn_getter, ExternPointer, FFIResult, NonOwnedPtrString, OwnedPtrString};
|
||||
use crate::ffi::{ffi_handle_arc_dyn_getter, FFIResult, NonOwnedPtrString, OwnedPtrString};
|
||||
use crate::static_data::{
|
||||
EffectParameter, MoveCategory, MoveData, MoveDataImpl, MoveTarget, SecondaryEffect, SecondaryEffectImpl,
|
||||
TypeIdentifier,
|
||||
@@ -64,7 +64,7 @@ unsafe extern "C" fn move_data_name(ptr: FFIHandle<Arc<dyn MoveData>>) -> FFIRes
|
||||
let move_data = ptr.from_ffi_handle();
|
||||
let name = move_data.name();
|
||||
match CString::new(name.str()) {
|
||||
Ok(name) => FFIResult::ok(name.into_raw()),
|
||||
Ok(name) => FFIResult::ok(OwnedPtrString(name.into_raw())),
|
||||
Err(_) => FFIResult::err_from_str("Unable to convert name to string"),
|
||||
}
|
||||
}
|
||||
@@ -90,9 +90,9 @@ unsafe extern "C" fn move_data_secondary_effect(
|
||||
|
||||
/// Arbitrary flags that can be applied to the move.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn move_data_has_flag(ptr: ExternPointer<Arc<dyn MoveData>>, flag: *const c_char) -> u8 {
|
||||
unsafe extern "C" fn move_data_has_flag(ptr: FFIHandle<Arc<dyn MoveData>>, flag: *const c_char) -> u8 {
|
||||
let flag = CStr::from_ptr(flag).into();
|
||||
u8::from(ptr.as_ref().has_flag(&flag))
|
||||
u8::from(ptr.from_ffi_handle().has_flag(&flag))
|
||||
}
|
||||
|
||||
/// Instantiates a new Secondary Effect.
|
||||
@@ -119,37 +119,37 @@ unsafe extern "C" fn secondary_effect_new(
|
||||
|
||||
/// The chance the effect triggers.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn secondary_effect_chance(ptr: ExternPointer<Box<dyn SecondaryEffect>>) -> f32 {
|
||||
ptr.as_ref().chance()
|
||||
unsafe extern "C" fn secondary_effect_chance(ptr: FFIHandle<Arc<dyn SecondaryEffect>>) -> f32 {
|
||||
ptr.from_ffi_handle().chance()
|
||||
}
|
||||
|
||||
/// The name of the effect.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn secondary_effect_effect_name(
|
||||
ptr: ExternPointer<Box<dyn SecondaryEffect>>,
|
||||
ptr: FFIHandle<Arc<dyn SecondaryEffect>>,
|
||||
) -> FFIResult<OwnedPtrString> {
|
||||
match CString::new(ptr.as_ref().effect_name().str()) {
|
||||
Ok(name) => FFIResult::ok(name.into_raw()),
|
||||
match CString::new(ptr.from_ffi_handle().effect_name().str()) {
|
||||
Ok(name) => FFIResult::ok(OwnedPtrString(name.into_raw())),
|
||||
Err(_) => FFIResult::err(anyhow!(
|
||||
"Unable to convert effect name '{}' to CString",
|
||||
ptr.as_ref().effect_name()
|
||||
ptr.from_ffi_handle().effect_name()
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The length of parameters of the effect.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn secondary_effect_parameter_length(ptr: ExternPointer<Box<dyn SecondaryEffect>>) -> usize {
|
||||
ptr.as_ref().parameters().len()
|
||||
unsafe extern "C" fn secondary_effect_parameter_length(ptr: FFIHandle<Arc<dyn SecondaryEffect>>) -> usize {
|
||||
ptr.from_ffi_handle().parameters().len()
|
||||
}
|
||||
|
||||
/// Get a parameter of the effect.
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn secondary_effect_parameter_get(
|
||||
ptr: ExternPointer<Box<dyn SecondaryEffect>>,
|
||||
ptr: FFIHandle<Arc<dyn SecondaryEffect>>,
|
||||
index: usize,
|
||||
) -> FFIHandle<Arc<EffectParameter>> {
|
||||
if let Some(v) = ptr.as_ref().parameters().get(index) {
|
||||
if let Some(v) = ptr.from_ffi_handle().parameters().get(index) {
|
||||
FFIHandle::get_handle(v.clone().into())
|
||||
} else {
|
||||
FFIHandle::none()
|
||||
|
||||
Reference in New Issue
Block a user