Major rework of extern ref system for WASM, fixes most possible panics in WASM handling
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
@@ -9,18 +9,18 @@ use std::sync::Arc;
|
||||
/// Instantiates a new DynamicLibrary with given parameters.
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_new(
|
||||
static_data: OwnedPtr<Box<dyn StaticData>>,
|
||||
stat_calculator: OwnedPtr<Box<dyn BattleStatCalculator>>,
|
||||
damage_library: OwnedPtr<Box<dyn DamageLibrary>>,
|
||||
misc_library: OwnedPtr<Box<dyn MiscLibrary>>,
|
||||
static_data: OwnedPtr<Arc<dyn StaticData>>,
|
||||
stat_calculator: OwnedPtr<Arc<dyn BattleStatCalculator>>,
|
||||
damage_library: OwnedPtr<Arc<dyn DamageLibrary>>,
|
||||
misc_library: OwnedPtr<Arc<dyn MiscLibrary>>,
|
||||
script_resolver: OwnedPtr<Box<dyn ScriptResolver>>,
|
||||
) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
|
||||
unsafe {
|
||||
let a: Arc<dyn DynamicLibrary> = Arc::new(DynamicLibraryImpl::new(
|
||||
*Box::from_raw(static_data),
|
||||
*Box::from_raw(stat_calculator),
|
||||
*Box::from_raw(damage_library),
|
||||
*Box::from_raw(misc_library),
|
||||
static_data.read(),
|
||||
stat_calculator.read(),
|
||||
damage_library.read(),
|
||||
misc_library.read(),
|
||||
*Box::from_raw(script_resolver),
|
||||
));
|
||||
a.into()
|
||||
@@ -37,8 +37,8 @@ extern "C" fn dynamic_library_drop(ptr: OwnedPtr<Arc<dyn DynamicLibrary>>) {
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_static_data(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn StaticData>> {
|
||||
ptr.as_ref().static_data().into()
|
||||
) -> IdentifiablePointer<Arc<dyn StaticData>> {
|
||||
ptr.as_ref().static_data().clone().into()
|
||||
}
|
||||
|
||||
/// The stat calculator deals with the calculation of flat and boosted stats, based on the
|
||||
@@ -46,16 +46,16 @@ extern "C" fn dynamic_library_get_static_data(
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_stat_calculator(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn BattleStatCalculator>> {
|
||||
ptr.as_ref().stat_calculator().into()
|
||||
) -> IdentifiablePointer<Arc<dyn BattleStatCalculator>> {
|
||||
ptr.as_ref().stat_calculator().clone().into()
|
||||
}
|
||||
|
||||
/// The damage calculator deals with the calculation of things relating to damage.
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_damage_calculator(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn DamageLibrary>> {
|
||||
ptr.as_ref().damage_calculator().into()
|
||||
) -> IdentifiablePointer<Arc<dyn DamageLibrary>> {
|
||||
ptr.as_ref().damage_calculator().clone().into()
|
||||
}
|
||||
|
||||
/// The Misc Library holds minor functions that do not fall in any of the other libraries and
|
||||
@@ -63,6 +63,6 @@ extern "C" fn dynamic_library_get_damage_calculator(
|
||||
#[no_mangle]
|
||||
extern "C" fn dynamic_library_get_misc_library(
|
||||
ptr: ExternPointer<Arc<dyn DynamicLibrary>>,
|
||||
) -> IdentifiablePointer<Box<dyn MiscLibrary>> {
|
||||
ptr.as_ref().misc_library().into()
|
||||
) -> IdentifiablePointer<Arc<dyn MiscLibrary>> {
|
||||
ptr.as_ref().misc_library().clone().into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user