Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,33 @@ namespace Tutorial
{
static void Main(string[] args)
{
using var host = new Host();
using var store = new Store();

using var module = store.LoadModuleText(
"hello",
"(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))"
);

using var host = new Host(store);

host.DefineFunction(
"",
"hello",
() => Console.WriteLine("Hello from C#!")
);

using var module = host.LoadModuleText(
"hello",
"(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))"
);

using dynamic instance = host.Instantiate(module);
instance.run();
}
}
}
```

This host defines a function called `hello` that simply prints a hello message.
A `Store` is created and the WebAssembly module, in text format, is loaded into the store.

A `Host` defines a function called `hello` that simply prints a hello message.

It then loads the module into the host in WebAssembly text format and invokes the module's `run` export.
The module is instantiated into the host and the module's `run` export is invoked.

To run the application, simply use `dotnet`:

Expand Down
6 changes: 3 additions & 3 deletions docs/articles/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ namespace Tutorial
{
static void Main(string[] args)
{
using var host = new Host();
using var store = new Store();
using var module = store.LoadModuleText("hello", "(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))");
using var host = new Host(store);

host.DefineFunction(
"",
"hello",
() => Console.WriteLine("Hello from C#!")
);

using var module = host.LoadModuleText("hello", "(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))");

using dynamic instance = host.Instantiate(module);
instance.run();
}
Expand Down
6 changes: 3 additions & 3 deletions examples/global/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Program
{
static void Main(string[] args)
{
using var host = new Host();
using var store = new Store();
using var module = store.LoadModuleText("global.wat");
using var host = new Host(store);

var global = host.DefineMutableGlobal("", "global", 1);

Expand All @@ -19,8 +21,6 @@ static void Main(string[] args)
}
);

using var module = host.LoadModuleText("global.wat");

using dynamic instance = host.Instantiate(module);
instance.run(20);
}
Expand Down
6 changes: 3 additions & 3 deletions examples/hello/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ class Program
{
static void Main(string[] args)
{
using var host = new Host();
using var store = new Store();
using var module = store.LoadModuleText("hello.wat");
using var host = new Host(store);

host.DefineFunction(
"",
"hello",
() => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModuleText("hello.wat");

using dynamic instance = host.Instantiate(module);
instance.run();
}
Expand Down
6 changes: 3 additions & 3 deletions examples/memory/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Program
{
static void Main(string[] args)
{
using var host = new Host();
using var store = new Store();
using var module = store.LoadModuleText("memory.wat");
using var host = new Host(store);

host.DefineFunction(
"",
Expand All @@ -18,8 +20,6 @@ static void Main(string[] args)
}
);

using var module = host.LoadModuleText("memory.wat");

using dynamic instance = host.Instantiate(module);
instance.run();
}
Expand Down
Loading