diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-12-05 17:21:33 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-12-06 12:27:28 -0700 |
| commit | 4451786c664ff4c0af11d76889b3f4f580134b38 (patch) | |
| tree | f91167c49e19d59bea7ce31926c8635b73e32394 /doc | |
| parent | 823d1e70876d79dfae9dde0496e7cf293995c44a (diff) | |
| download | zig-4451786c664ff4c0af11d76889b3f4f580134b38.tar.gz zig-4451786c664ff4c0af11d76889b3f4f580134b38.zip | |
langref: update WASI preopens example
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/langref.html.in | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in index bf2a6fd71d..b2e408dda7 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -10961,24 +10961,28 @@ pub fn main() !void { {#code_begin|exe|preopens#} {#target_wasi#} const std = @import("std"); -const PreopenList = std.fs.wasi.PreopenList; +const fs = std.fs; pub fn main() !void { var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; const gpa = general_purpose_allocator.allocator(); - var preopens = PreopenList.init(gpa); - defer preopens.deinit(); + var arena_instance = std.heap.ArenaAllocator.init(gpa); + defer arena_instance.deinit(); + const arena = arena_instance.allocator(); - try preopens.populate(null); + const preopens = try fs.wasi.preopensAlloc(arena); - for (preopens.asSlice()) |preopen, i| { - std.debug.print("{}: {}\n", .{ i, preopen }); + for (preopens.names) |preopen, i| { + std.debug.print("{}: {s}\n", .{ i, preopen }); } } {#code_end#} {#shell_samp#}$ wasmtime --dir=. preopens.wasm -0: Preopen{ .fd = 3, .type = PreopenType{ .Dir = '.' } } +0: stdin +1: stdout +2: stderr +3: . {#end_shell_samp#} {#header_close#} {#header_close#} |
