PkmnLib_rs/src/ffi/static_data/statistic_set.rs

100 lines
2.6 KiB
Rust

use crate::ffi::FFIHandle;
use crate::ffi::FromFFIHandle;
use crate::static_data::{StaticStatisticSet, Statistic, StatisticSet};
use std::sync::Arc;
/// Basic foreign function interface for a statistic set.
macro_rules! statistic_set {
($num_type:ident) => {
paste::paste!{
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _new>](
hp: $num_type,
attack: $num_type,
defense: $num_type,
special_attack: $num_type,
special_defense: $num_type,
speed: $num_type,
) -> FFIHandle<Arc<StatisticSet<$num_type>>> {
FFIHandle::get_handle(Arc::new(StatisticSet::new(
hp,
attack,
defense,
special_attack,
special_defense,
speed,
)).into())
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _get_stat>](ptr: FFIHandle<Arc<StatisticSet<$num_type>>>, stat: Statistic) -> $num_type {
ptr.from_ffi_handle().get_stat(stat)
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _set_stat>](ptr: FFIHandle<Arc<StatisticSet<$num_type>>>, stat: Statistic, value: $num_type) {
ptr.from_ffi_handle().set_stat(stat, value)
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _increase_stat>](ptr: FFIHandle<Arc<StatisticSet<$num_type>>>, stat: Statistic, value: $num_type) {
ptr.from_ffi_handle().increase_stat(stat, value)
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _decrease_stat>](ptr: FFIHandle<Arc<StatisticSet<$num_type>>>, stat: Statistic, value: $num_type) {
ptr.from_ffi_handle().decrease_stat(stat, value)
}
}
};
}
statistic_set!(u8);
// statistic_set!(u16);
statistic_set!(u32);
statistic_set!(i8);
// statistic_set!(i16);
// statistic_set!(i32);
/// Basic foreign function interface for a static statistic set.
macro_rules! static_statistic_set {
($num_type:ident) => {
paste::paste!{
#[no_mangle]
extern "C" fn [<static_statistic_set_ $num_type _new>](
hp: $num_type,
attack: $num_type,
defense: $num_type,
special_attack: $num_type,
special_defense: $num_type,
speed: $num_type,
) -> FFIHandle<Arc<StaticStatisticSet<$num_type>>> {
FFIHandle::get_handle(Arc::new(StaticStatisticSet::new(
hp,
attack,
defense,
special_attack,
special_defense,
speed,
)).into())
}
#[no_mangle]
extern "C" fn [<static_statistic_set_ $num_type _get_stat>](ptr: FFIHandle<Arc<StaticStatisticSet<$num_type>>>, stat: Statistic) -> $num_type {
ptr.from_ffi_handle().get_stat(stat)
}
}
};
}
// static_statistic_set!(u8);
static_statistic_set!(u16);
// static_statistic_set!(u32);
// static_statistic_set!(i8);
// static_statistic_set!(i16);
// static_statistic_set!(i32);