#include <fstream>
#include <iostream>
#include <sstream>
using namespace wasmtime;
std::string readFile(const char *name) {
std::ifstream watFile;
watFile.open(name);
std::stringstream strStream;
strStream << watFile.rdbuf();
return strStream.str();
}
int main() {
std::cout << "Compiling module\n";
auto module =
Module::compile(engine, readFile("examples/hello.wat")).unwrap();
std::cout << "Initializing...\n";
std::cout << "Creating callback...\n";
Func::wrap(store, []() { std::cout << "Calling back...\n"; });
std::cout << "Instantiating module...\n";
auto instance = Instance::create(store, module, {host_func}).unwrap();
std::cout << "Extracting export...\n";
auto run = std::get<Func>(*instance.get(store, "run"));
std::cout << "Calling export...\n";
run.call(store, {}).unwrap();
std::cout << "Done\n";
}
Global compilation state in Wasmtime.
Definition: wasmtime.hh:645
Representation of a WebAssembly function.
Definition: wasmtime.hh:2505
Owner of all WebAssembly objects.
Definition: wasmtime.hh:1820