Fixes for FFI.
This commit is contained in:
45
src/ffi/static_data/libraries/growth_rate_library.rs
Normal file
45
src/ffi/static_data/libraries/growth_rate_library.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use crate::defines::LevelInt;
|
||||
use crate::ffi::{BorrowedPtr, ExternPointer, OwnedPtr};
|
||||
use crate::static_data::{GrowthRate, GrowthRateLibrary};
|
||||
use std::ffi::{c_char, CStr};
|
||||
use std::ptr::drop_in_place;
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn growth_rate_library_new(capacity: usize) -> OwnedPtr<GrowthRateLibrary> {
|
||||
Box::into_raw(Box::new(GrowthRateLibrary::new(capacity)))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_drop(ptr: OwnedPtr<GrowthRateLibrary>) {
|
||||
drop_in_place(ptr)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_calculate_level(
|
||||
ptr: ExternPointer<GrowthRateLibrary>,
|
||||
growth_rate: BorrowedPtr<c_char>,
|
||||
experience: u32,
|
||||
) -> LevelInt {
|
||||
ptr.as_ref()
|
||||
.calculate_level(&CStr::from_ptr(growth_rate).into(), experience)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_calculate_experience(
|
||||
ptr: ExternPointer<GrowthRateLibrary>,
|
||||
growth_rate: BorrowedPtr<c_char>,
|
||||
level: LevelInt,
|
||||
) -> u32 {
|
||||
ptr.as_ref()
|
||||
.calculate_experience(&CStr::from_ptr(growth_rate).into(), level)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn growth_rate_library_add_growth_rate(
|
||||
ptr: ExternPointer<GrowthRateLibrary>,
|
||||
name: BorrowedPtr<c_char>,
|
||||
growth_rate: OwnedPtr<Box<dyn GrowthRate>>,
|
||||
) {
|
||||
ptr.as_mut()
|
||||
.add_growth_rate(&CStr::from_ptr(name).into(), *Box::from_raw(growth_rate));
|
||||
}
|
||||
Reference in New Issue
Block a user