Clippy fixes, additional WASM registration work
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-08-26 18:23:35 +02:00
parent 1e43c07d43
commit c5fb81c179
22 changed files with 219 additions and 101 deletions

View File

@@ -10,16 +10,18 @@ use crate::script_implementations::wasm::script_resolver::WebAssemblyEnvironment
use crate::static_data::EffectParameter;
use crate::StringKey;
/// A macro to generate the script function cache a bit easier.
macro_rules! script_function_cache {
(
$(
$name:ident -> $return:ty
$name:ident($($par_type:ty),*$(,)?)
)*
) => {
#[derive(Default)]
#[allow(unused_parens)]
pub struct ScriptFunctionCache {
$(
$name: RwLock<Option<$return>>,
$name: RwLock<Option<NativeFunc<(u32$(, $par_type)*), ()>>>,
)*
}
@@ -27,20 +29,22 @@ macro_rules! script_function_cache {
$(
paste! {
#[cold]
#[allow(unused_parens)]
fn [<initialize_ $name>](&self, env: &Arc<WebAssemblyEnvironmentData>) {
let exported = env.exported_functions();
let f = exported.get::<StringKey>(&stringify!([< script_ $name >]).into());
if let Some(f) = f {
let func: $return = f.native().unwrap();
let func: NativeFunc<(u32 $(,$par_type)*), ()> = f.native().unwrap();
let _ = self.$name.write().insert(func);
}
}
#[allow(unused_parens)]
pub(crate) fn [<$name>](
&self,
env: &Arc<WebAssemblyEnvironmentData>,
) -> Option<$return> {
) -> Option<NativeFunc<(u32 $(,$par_type)*), ()>> {
{
let read_lock = self.$name.read();
if let Some(f) = read_lock.as_ref() {
@@ -57,6 +61,10 @@ macro_rules! script_function_cache {
}
script_function_cache! {
on_initialize -> NativeFunc<(u32, ExternRef<DynamicLibrary>, VecExternRef<EffectParameter>), ()>
on_before_turn -> NativeFunc<(u32, ExternRef<TurnChoice>), ()>
stack()
on_remove()
on_initialize(ExternRef<DynamicLibrary>, VecExternRef<EffectParameter>)
on_before_turn(ExternRef<TurnChoice>)
change_speed(ExternRef<TurnChoice>, u32)
change_priority(ExternRef<TurnChoice>, u32)
}