| 14 | } |
| 15 | |
| 16 | int main() { |
| 17 | // Load our WebAssembly (parsed WAT in our case), and then load it into a |
| 18 | // `Module` which is attached to a `Store`. After we've got that we |
| 19 | // can instantiate it. |
| 20 | Engine engine; |
| 21 | Store store(engine); |
| 22 | auto module = Module::compile(engine, readFile("examples/gcd.wat")).unwrap(); |
| 23 | auto instance = Instance::create(store, module, {}).unwrap(); |
| 24 | |
| 25 | // Invoke `gcd` export |
| 26 | auto gcd = std::get<Func>(*instance.get(store, "gcd")); |
| 27 | auto results = gcd.call(store, {6, 27}).unwrap(); |
| 28 | |
| 29 | std::cout << "gcd(6, 27) = " << results[0].i32() << "\n"; |
| 30 | } |