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.
29 lines
646 B
C#
29 lines
646 B
C#
using System;
|
|
using Wasmtime;
|
|
|
|
namespace HelloExample
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
using var host = new Host();
|
|
|
|
var global = host.DefineMutableGlobal("", "global", 1);
|
|
|
|
host.DefineFunction(
|
|
"",
|
|
"print_global",
|
|
() => {
|
|
Console.WriteLine($"The value of the global is: {global.Value}.");
|
|
}
|
|
);
|
|
|
|
using var module = host.LoadModule("global.wasm");
|
|
|
|
using dynamic instance = host.Instantiate(module);
|
|
instance.run(20);
|
|
}
|
|
}
|
|
}
|