Registration fixes and improvements.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-09-16 11:01:37 +02:00
parent b1890681a1
commit 7bcfd92d45
20 changed files with 397 additions and 52 deletions

View File

@@ -21,6 +21,8 @@ macro_rules! script_function_cache {
#[derive(Default)]
#[allow(unused_parens)]
pub(super) struct ScriptFunctionCache {
script_get_name: RwLock<Option<TypedFunction<(u32), u32>>>,
dealloc_cstring: RwLock<Option<TypedFunction<(u32), ()>>>,
$(
$name: RwLock<Option<TypedFunction<(u32$(, $par_type)*), ()>>>,
)*
@@ -168,5 +170,42 @@ script_function_cache! {
share_experience(ExternRef<Pokemon>, ExternRef<Pokemon>, WasmPtr<bool>)
block_weather(ExternRef<Battle>, WasmPtr<bool>)
change_capture_rate_bonus(ExternRef<Pokemon>, ExternRef<Item>, WasmPtr<u8>)
}
impl ScriptFunctionCache {
pub(crate) fn script_get_name(&self, env: &Arc<WebAssemblyEnvironmentData>) -> Option<TypedFunction<u32, u32>> {
{
let read_lock = self.script_get_name.read();
if let Some(f) = read_lock.as_ref() {
return Some(f.clone());
}
}
{
let exported = env.exported_functions();
let f = exported.get::<StringKey>(&"script_get_name".into());
if let Some(f) = f {
let func: TypedFunction<u32, u32> = f.typed(&env.store_ref()).unwrap();
let _ = self.script_get_name.write().insert(func);
}
}
self.script_get_name.read().as_ref().cloned()
}
pub(crate) fn dealloc_cstring(&self, env: &Arc<WebAssemblyEnvironmentData>) -> Option<TypedFunction<u32, ()>> {
{
let read_lock = self.dealloc_cstring.read();
if let Some(f) = read_lock.as_ref() {
return Some(f.clone());
}
}
{
let exported = env.exported_functions();
let f = exported.get::<StringKey>(&"dealloc_cstring".into());
if let Some(f) = f {
let func: TypedFunction<u32, ()> = f.typed(&env.store_ref()).unwrap();
let _ = self.dealloc_cstring.write().insert(func);
}
}
self.dealloc_cstring.read().as_ref().cloned()
}
}