diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-12-19 19:15:05 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-12-23 22:15:11 -0800 |
| commit | 7d955274bb40bc937275b3d59c6304dd44c85d40 (patch) | |
| tree | e22f6f6d07fe18915ec2f954596caf79f71e11d3 /lib/init/src/main.zig | |
| parent | 2e4a6c88b535f049fd52a84d9b9e510cf70a42fd (diff) | |
| download | zig-7d955274bb40bc937275b3d59c6304dd44c85d40.tar.gz zig-7d955274bb40bc937275b3d59c6304dd44c85d40.zip | |
update the init templates to new std API
Diffstat (limited to 'lib/init/src/main.zig')
| -rw-r--r-- | lib/init/src/main.zig | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/init/src/main.zig b/lib/init/src/main.zig index 88dd8348e1..9df441b564 100644 --- a/lib/init/src/main.zig +++ b/lib/init/src/main.zig @@ -1,10 +1,32 @@ const std = @import("std"); +const Io = std.Io; + const _NAME = @import(".NAME"); pub fn main() !void { - // Prints to stderr, ignoring potential errors. + // Prints to stderr, unbuffered, ignoring potential errors. std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); - try _NAME.bufferedPrint(); + + // In order to allocate memory we must construct an `Allocator` instance. + var debug_allocator: std.heap.DebugAllocator(.{}) = .init; + defer _ = debug_allocator.deinit(); // This checks for leaks. + const gpa = debug_allocator.allocator(); + + // In order to do I/O operations we must construct an `Io` instance. + var threaded: std.Io.Threaded = .init(gpa); + defer threaded.deinit(); + const io = threaded.io(); + + // Stdout is for the actual output of your application, for example if you + // are implementing gzip, then only the compressed bytes should be sent to + // stdout, not any debugging messages. + var stdout_buffer: [1024]u8 = undefined; + var stdout_file_writer: Io.File.Writer = .init(.stdout(), io, &stdout_buffer); + const stdout_writer = &stdout_file_writer.interface; + + try _NAME.printAnotherMessage(stdout_writer); + + try stdout_writer.flush(); // Don't forget to flush! } test "simple test" { |
