From 4451786c664ff4c0af11d76889b3f4f580134b38 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 5 Dec 2022 17:21:33 -0700 Subject: [PATCH] langref: update WASI preopens example --- doc/langref.html.in | 18 +++++++++++------- 1 file 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#}