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 []( hp: $num_type, attack: $num_type, defense: $num_type, special_attack: $num_type, special_defense: $num_type, speed: $num_type, ) -> FFIHandle>> { FFIHandle::get_handle(Arc::new(StatisticSet::new( hp, attack, defense, special_attack, special_defense, speed, )).into()) } #[no_mangle] extern "C" fn [](ptr: FFIHandle>>, stat: Statistic) -> $num_type { ptr.from_ffi_handle().get_stat(stat) } #[no_mangle] extern "C" fn [](ptr: FFIHandle>>, stat: Statistic, value: $num_type) { ptr.from_ffi_handle().set_stat(stat, value) } #[no_mangle] extern "C" fn [](ptr: FFIHandle>>, stat: Statistic, value: $num_type) { ptr.from_ffi_handle().increase_stat(stat, value) } #[no_mangle] extern "C" fn [](ptr: FFIHandle>>, 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 []( hp: $num_type, attack: $num_type, defense: $num_type, special_attack: $num_type, special_defense: $num_type, speed: $num_type, ) -> FFIHandle>> { FFIHandle::get_handle(Arc::new(StaticStatisticSet::new( hp, attack, defense, special_attack, special_defense, speed, )).into()) } #[no_mangle] extern "C" fn [](ptr: FFIHandle>>, 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);