#include "WebAssemblyBattleScript.hpp" #include "WebAssemblyFunctionCall.hpp" #include "WebAssemblyScriptResolver.hpp" WebAssemblyBattleScript::~WebAssemblyBattleScript() { // Ensure the WebAssembly library can clear up its own junk auto funcOpt = _resolver->GetFunction<1, 0>("destroy_script"); if (funcOpt.has_value()) { auto& func = funcOpt.value(); func.Loadi32(0, _wasmPtr); func.Call(); } // Remove the backwards lookup to this script. _resolver->RemoveRegisteredScript(_wasmPtr); } #define WASM_CALL(capability, script_name, args_count, return_count, parameter_setup) \ if (!HasCapability(WebAssemblyScriptCapabilities::capability)) { \ return; \ } \ auto funcOpt = _resolver->GetFunction(script_name); \ if (!funcOpt.has_value()) { \ return; \ } \ auto& func = funcOpt.value(); \ parameter_setup; \ func.Call(); void WebAssemblyBattleScript::OnInitialize(const CreatureLib::Battling::BattleLibrary* library, const ArbUt::List&) { WASM_CALL(Initialize, "script_on_initialize", 2, 0, { func.Loadi32(0, _wasmPtr); func.LoadExternRef(1, library); }); } CreatureLib::Battling::BattleScript* WebAssemblyBattleScript::Clone(const ArbUt::OptionalBorrowedPtr&) { // FIXME: Implement return nullptr; }