Initial work on WebAssembly script provider
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
40
src/ScriptResolving/WASM/WebAssemblyBattleScript.cpp
Normal file
40
src/ScriptResolving/WASM/WebAssemblyBattleScript.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#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<args_count, return_count>(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<CreatureLib::Library::EffectParameter*>&) {
|
||||
WASM_CALL(Initialize, "script_on_initialize", 2, 0, {
|
||||
func.Loadi32(0, _wasmPtr);
|
||||
func.LoadExternRef(1, library);
|
||||
});
|
||||
}
|
||||
|
||||
CreatureLib::Battling::BattleScript* WebAssemblyBattleScript::Clone(const ArbUt::OptionalBorrowedPtr<void>&) {
|
||||
// FIXME: Implement
|
||||
return nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user