PkmnLib_rs/src/ffi/static_data/statistic_set.rs

107 lines
2.7 KiB
Rust

use crate::ffi::{ExternPointer, OwnedPtr};
use crate::static_data::{StaticStatisticSet, Statistic, StatisticSet};
use std::ptr::drop_in_place;
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,
) -> OwnedPtr<StatisticSet<$num_type>> {
Box::into_raw(Box::new(StatisticSet::new(
hp,
attack,
defense,
special_attack,
special_defense,
speed,
)))
}
#[no_mangle]
unsafe extern "C" fn [<statistic_set_ $num_type _drop>](ptr: OwnedPtr<StatisticSet<$num_type>>) {
drop_in_place(ptr)
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _get_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic) -> $num_type {
ptr.as_ref().get_stat(stat)
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _set_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic, value: $num_type) {
ptr.as_ref().set_stat(stat, value)
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _increase_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic, value: $num_type) {
ptr.as_ref().increase_stat(stat, value)
}
#[no_mangle]
extern "C" fn [<statistic_set_ $num_type _decrease_stat>](ptr: ExternPointer<StatisticSet<$num_type>>, stat: Statistic, value: $num_type) {
ptr.as_ref().decrease_stat(stat, value)
}
}
};
}
statistic_set!(u8);
statistic_set!(u16);
statistic_set!(u32);
statistic_set!(i8);
statistic_set!(i16);
statistic_set!(i32);
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,
) -> OwnedPtr<StaticStatisticSet<$num_type>> {
Box::into_raw(Box::new(StaticStatisticSet::new(
hp,
attack,
defense,
special_attack,
special_defense,
speed,
)))
}
#[no_mangle]
unsafe extern "C" fn [<static_statistic_set_ $num_type _drop>](ptr: OwnedPtr<StaticStatisticSet<$num_type>>) {
drop_in_place(ptr)
}
#[no_mangle]
extern "C" fn [<static_statistic_set_ $num_type _get_stat>](ptr: ExternPointer<StaticStatisticSet<$num_type>>, stat: Statistic) -> $num_type {
ptr.as_ref().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);