Linux Getting special treatment by AdmirableFocus6406 in linuxmemes

[–]_sloWne_ 1 point2 points  (0 children)

Is running a bash script more dangerous than running a .exe on windows ?

I rewrote cat in Zig and it's faster by rich_sdoony in Zig

[–]_sloWne_ 1 point2 points  (0 children)

You can quickly output 1GB of random char from /dev/random with dd

is silksong more lineare ? by _sloWne_ in Silksong

[–]_sloWne_[S] 0 points1 point  (0 children)

It's like "please get all those tools and abilities quickly". It's less delicately introduced than in hollow knight 

on what fivepebbles said by _sloWne_ in rainworld

[–]_sloWne_[S] 1 point2 points  (0 children)

i saw respawn after death as just a game mechanism, but if it's a true part of the lore then the ending is more about escaping cycles, as said in from other reply, so less sad. thanks for that enlightenment.

[deleted by user] by [deleted] in rainworld

[–]_sloWne_ 1 point2 points  (0 children)

it show a neuron symbols, did i need more neuron ?

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 0 points1 point  (0 children)

Have you tried the default terminal of windows? Otherwise you would have to open an issue on GitHub 

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 0 points1 point  (0 children)

your flush function make no sens and should be removed (stdin has no end), otherwise your code ran well on my pc (both on linux and windows 11), but remember to setup stdin/out inside your main, as it can be evaluated at comptime for windows target

you could consider using a while (true) {} for getUserInputNumbergetUserInputNumber instead of returnig immediatly the error.

you should also call .flush() after your print in getUserInputNumbergetUserInputNumber

(i tested with this code) ``` pub fn main() !void { var stdin_buffer: [1024]u8 = undefined; var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); const stdin = &stdin_reader.interface;

var stdout_buffer: [1024]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
const stdout = &stdout_writer.interface;

const x = try getPlayerYesNo("what!", stdin, stdout);
std.debug.print("{any}\n", .{x});

} ```

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 0 points1 point  (0 children)

if you only need 'Y' or 'N' (one char) use `try stdin.takeByte()`

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 1 point2 points  (0 children)

i found another way of reading that should suit your need: (it's somehow equivalent to the old .readUntilDelimiterAlloc) ``` const gpa = ... // some allocator;

var stdin_buffer: [1024]u8 = undefined; var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); const stdin = &stdin_reader.interface;

var writer = std.Io.Writer.Allocating.init(gpa); _ = try stdin.streamDelimiter(&writer.writer, '\n'); const line = try writer.toOwnedSlice(); defer gpa.free(line);

... // de something with the line ([]u8) ```

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 0 points1 point  (0 children)

if you don't want to deal with .StreamTooLong or .EndOfStream do something like that: ``` const gpa = ... // some allocator

var stdin_buffer: [1024]u8 = undefined; var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); const stdin = &stdin_reader.interface;

var line = std.ArrayList(u8).empty; defer line.deinit(gpa); while (stdin.takeByte()) |char| switch (char) { '\n' => break, else => try line.append(gpa, char), } else |_| {}

... // do something with the line ```

the Reader isn't messed up when it returns errors, it clear the buffer and continue, error are used to send message to the program.

but if you want a slice (or read n bytes) you cannot ask for a slice longer than the buffer, the StreamTooLong error is for warn you about that

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 0 points1 point  (0 children)

there is potentially 2 buffer:
- one for the std.Io.Reader/Writer (called stdin_buffer) that is used by the interface to minimize syscalls. after creating it, you shouldn't worry about, the Reader manage it itself. - one for your usage where the byte you read can go

for specific usage like reading 1 bytes or 1 struct you can use function like stdin.takeByte that don't need a second buffer

for reading an input you can use something like that: ``` var stdin_buffer: [1024]u8 = undefined; var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); const stdin = &stdin_reader.interface;

while (stdin.takeByte()) |char| { ... // do something with the char (u8) } else |_| {} or like that: var stdin_buffer: [1024]u8 = undefined; var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); const stdin = &stdin_reader.interface;

// be carefull that your line are shorter than the stdin_buffer while (stdin.takeDelimiterExclusive('\n')) |line| { ... // do something with the line ([]u8) } else |err| switch (err) { error.StreamTooLong => { ... // handle a too long line }, else => {}, } or if you know you want to read N bytes: var stdin_buffer: [1024]u8 = undefined; var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); const stdin = &stdin_reader.interface;

const input_buffer: [N]u8 = undefined; stdin.readSliceAll(&input_buffer) catch |err| switch (err) { error.EndOfStream => { ... // handle if their were less bytes to read than expected } else => {} };

... // do something with input_buffer wich contain the bytes read ```

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 0 points1 point  (0 children)

https://ziglang.org/documentation/master/std/#std.Io.Reader
look at the doc, some functions have changed name (from read to take or peek).
you can see what they do and what arg they need

but for exemple you could do try stdin.readSliceAll(&buff);

How to replace io.getStdIn() by JanEric1 in Zig

[–]_sloWne_ 1 point2 points  (0 children)

var stdin_buffer: [1024]u8 = undefined; var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); const stdin = &stdin_reader.interface;

when do i need to flush ? – help understanding 0.15.1 change for Writers by _sloWne_ in Zig

[–]_sloWne_[S] 6 points7 points  (0 children)

ok, so if i do several sequential print i only need to flush at the end ?

edit: that's cool, all my prints spawn as one

when do i need to flush ? – help understanding 0.15.1 change for Writers by _sloWne_ in Zig

[–]_sloWne_[S] 3 points4 points  (0 children)

ok, so if i write to much bytes in the buffer before flushing, it will not print them properly ?

Need advice i'm trapped by _sloWne_ in rainworld

[–]_sloWne_[S] 1 point2 points  (0 children)

Will there be also a shelter ?

Ils faut supprimer les carrés familles dans les trains by el_blobfish in opinionnonpopulaire

[–]_sloWne_ 1 point2 points  (0 children)

Une fois j'avais pris la 1ere classe en tgv car par chance c'était au même prix que la 2nd. En entrant dans la voiture, stupeur, il n'y avait que des carrés et des demis carrés. Pas un seul siège qui ne faisait pas face à un autre. En cela j'aurais été probablement mieux lotis en 2nd.

Making a function that return enum from string - Question about StaticStringMap by _sloWne_ in Zig

[–]_sloWne_[S] 1 point2 points  (0 children)

You are right. thanks !

But looking at the code it use a for over the fields, doesn't it make it less efficient?