aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2020-06-11 22:06:57 +0200
committerJakub Konka <kubkon@jakubkonka.com>2020-06-11 22:30:02 +0200
commite4a8598ddda0d0ff289ac59a04f2ac965ef7e102 (patch)
tree2a989ed48915da0a4d7533673e2c84bf094a4f4a /doc
parenta282ac7a9119cd0961ea17e29c4a0e9b0baf60d0 (diff)
downloadzig-e4a8598ddda0d0ff289ac59a04f2ac965ef7e102.tar.gz
zig-e4a8598ddda0d0ff289ac59a04f2ac965ef7e102.zip
Add doc example for extracting WASI preopens
Diffstat (limited to 'doc')
-rw-r--r--doc/langref.html.in27
1 files changed, 24 insertions, 3 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index e5c814d663..f3fd1d9e8c 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -9702,7 +9702,7 @@ The result is 3</code></pre>
{#header_open|WASI#}
<p>Zig's support for WebAssembly System Interface (WASI) is under active development.
Example of using the standard library and reading command line arguments:</p>
- {#code_begin|exe|wasi#}
+ {#code_begin|exe|args#}
{#target_wasi#}
const std = @import("std");
@@ -9716,10 +9716,31 @@ pub fn main() !void {
}
}
{#code_end#}
- <pre><code>$ wasmer run wasi.wasm 123 hello
-0: wasi.wasm
+ <pre><code>$ wasmtime args.wasm 123 hello
+0: args.wasm
1: 123
2: hello</code></pre>
+ <p>A more interesting example would be extracting the list of preopens from the runtime.
+ This is now supported in the standard library via {#syntax#}std.fs.wasi.PreopenList{#endsyntax#}:</p>
+ {#code_begin|exe|preopens#}
+ {#target_wasi#}
+const std = @import("std");
+const PreopenList = std.fs.wasi.PreopenList;
+
+pub fn main() !void {
+ var preopens = PreopenList.init(std.heap.page_allocator);
+ defer preopens.deinit();
+
+ try preopens.populate();
+
+ for (preopens.asSlice()) |preopen, i| {
+ std.debug.warn("{}: {}\n", .{ i, preopen });
+ }
+}
+ {#code_end#}
+ <pre><code>$ wasmtime --dir=. preopens.wasm
+0: { .fd = 3, .Dir = '.' }
+</code></pre>
{#header_close#}
{#header_close#}
{#header_open|Targets#}