Files
wasmtime/crates/misc/dotnet/examples/memory/Program.cs
Peter Huene cf1d9ee857 Reimplement the C# API.
This commit reimplements the C# API in terms of a Wasmtime linker.

It removes the custom binding implementation that was based on reflection in
favor of the linker's implementation.

This should make the C# API a little closer to the Rust API.

The `Engine` and `Store` types have been hidden behind the `Host` type which is
responsible for hosting WebAssembly module instances.

Documentation and tests have been updated.
2020-03-25 18:47:59 -07:00

28 lines
683 B
C#

using System;
using Wasmtime;
namespace HelloExample
{
class Program
{
static void Main(string[] args)
{
using var host = new Host();
host.DefineFunction(
"",
"log",
(Caller caller, int address, int length) => {
var message = caller.GetMemory("mem").ReadString(address, length);
Console.WriteLine($"Message from WebAssembly: {message}");
}
);
using var module = host.LoadModule("memory.wasm");
using dynamic instance = host.Instantiate(module);
instance.run();
}
}
}