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:
@@ -0,0 +1,39 @@
|
||||
#include "LibraryMethods.hpp"
|
||||
#include <type_traits>
|
||||
#include "../../../../Battling/Library/BattleLibrary.hpp"
|
||||
#include "../../WebAssemblyScriptResolver.hpp"
|
||||
#include "../WasmHelperFile.hpp"
|
||||
#include "wasm.h"
|
||||
|
||||
wasm_func_t* MoveLibrary_GetMoveByHash(wasm_store_t* store) {
|
||||
wasm_functype_t* type =
|
||||
wasm_functype_new_2_1(wasm_valtype_new_i64(), wasm_valtype_new_i32(), wasm_valtype_new_i64());
|
||||
auto* f = wasm_func_new(store, type, [](const wasm_val_vec_t* args, wasm_val_vec_t* returns) -> wasm_trap_t* {
|
||||
auto moveLibrary = (PkmnLib::Library::MoveLibrary*)args->data[0].of.i64;
|
||||
auto hash = (u32)args->data[1].of.i32;
|
||||
auto opt = moveLibrary->TryGet(hash);
|
||||
if (!opt.has_value()) {
|
||||
returns->data[0] = WASM_I64_VAL(0);
|
||||
} else{
|
||||
returns->data[0] = WASM_I64_VAL(reinterpret_cast<i64>(moveLibrary->Get(hash).GetRaw()));
|
||||
}
|
||||
return nullptr;
|
||||
});
|
||||
wasm_functype_delete(type);
|
||||
return f;
|
||||
}
|
||||
|
||||
void LibraryMethods::Register(wasm_store_t* store, ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||
WebAssemblyScriptResolver* resolver) {
|
||||
REGISTER_GETTER("battling_battle_library_get_data_library", PkmnLib::Battling::BattleLibrary, GetStaticLib, store,
|
||||
resolver);
|
||||
REGISTER_GETTER("library_data_library_get_move_library", PkmnLib::Library::PokemonLibrary, GetMoveLibrary, store,
|
||||
resolver);
|
||||
externs.Insert("library_move_library_get_move_by_hash", MoveLibrary_GetMoveByHash(store));
|
||||
|
||||
REGISTER_GETTER("library_move_data_get_base_power", CreatureLib::Library::AttackData, GetBasePower, store,
|
||||
resolver);
|
||||
|
||||
REGISTER_GETTER("library_move_data_get_name", CreatureLib::Library::AttackData, GetName, store,
|
||||
resolver);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef PKMNLIB_LIBRARYMETHODS_H
|
||||
#define PKMNLIB_LIBRARYMETHODS_H
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <wasm.h>
|
||||
|
||||
class WebAssemblyScriptResolver;
|
||||
class LibraryMethods {
|
||||
public:
|
||||
static void Register(wasm_store_t* store, ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||
WebAssemblyScriptResolver* resolver);
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_LIBRARYMETHODS_H
|
||||
Reference in New Issue
Block a user