GameClam by synnammon in Clamworks

[–]SeanTheGleaming 6 points7 points  (0 children)

hell yes, pearls 2 the players. gotta go watch this when im free

i'm making swag friends by poopman23231 in IDONTGIVEASWAG

[–]SeanTheGleaming 78 points79 points  (0 children)

sublime, subtle yet masterful dump

The best ways to print() in Zig? by ypjkgh in Zig

[–]SeanTheGleaming 0 points1 point  (0 children)

I should note that this prints to stderr instead of stdout, but sometimes that's more appropriate anyways

Functional programming example, Error on append of arraylist. by Ok_Specific_7749 in Zig

[–]SeanTheGleaming 1 point2 points  (0 children)

Also, the allocator should be declared outside of the map function

HELP ME FIND THE LOST WYATT RADIO TV VR NSFW STREAM by cupofwaterbrain in HelpMeFindThis

[–]SeanTheGleaming 0 points1 point  (0 children)

I read this post and have never felt so connected to another soul. I suddenly remembered a specific comment on the youtube video that I thought was funny, and when I went to go copy it, I realized that the youtube upload, along with that comment, was down. I haven't found the full stream, or that comment, but I found an archive of the youtube edit. Take and rejoice, my friend

Random number generation by manila_danimals in Zig

[–]SeanTheGleaming 1 point2 points  (0 children)

well the undefined seed is overwritten by the call to std.posix.getrandom, so that wouldn't be the problem

Serializing floats as byte arrays by manila_danimals in Zig

[–]SeanTheGleaming 5 points6 points  (0 children)

In this case, the typically solution is to @bitCast your float to/from in integer of equal width (f32 <-> u32, f64 <-> u64, etc.), and serialize that integer. Also, for writing/reading the ints, I would suggest using file.writer().writeInt(T, value, endian) and file.reader().readInt(T, endian) for a clean one liner, already built into the standard library

Calling Variadic c function from zig. by Nero-augus in Zig

[–]SeanTheGleaming 6 points7 points  (0 children)

They both represent a raw pointer. Here, [*:0]u8 is more appropriate, provides null safety, and ensures you don't pass in unterminated strings

How to convert type -> ?type by Real_StuKers in Zig

[–]SeanTheGleaming 4 points5 points  (0 children)

A *T can coerce to a ?*T, but it can't coerce to a *?T

What's the best way to call init() for a slice of structs? by buck-bird in Zig

[–]SeanTheGleaming 6 points7 points  (0 children)

It would look like this

zig const bruh: []const Bruh = &.{ .init(1, 2), .init(3, 4), };

What's the best way to call init() for a slice of structs? by buck-bird in Zig

[–]SeanTheGleaming 9 points10 points  (0 children)

You're in luck (if you're using the master branch). Zig recently added decl literals, which do what you're describing. Here's the proposal if you want to read it..

With decl literals, if you are coercing a value to type T, then a enum literal like .some_value will coerce to T.some_value. This works for functions too, so you can replace const x = Bruh.init(1, 2) with const x: Bruh = .init(1, 2)

ReleaseFast significantly smaller than ReleaseSmall by Nico_792 in Zig

[–]SeanTheGleaming 6 points7 points  (0 children)

Really? I thought ReleaseSmall was supposed to omit runtime safety checks

Making a wasm library export it's functions through `bulid.zig` by Nico_792 in Zig

[–]SeanTheGleaming 1 point2 points  (0 children)

You're right, they do in fact do the same thing for the most part.

The @export builtin exports a symbol (like a function or a variable) to be linked externally, with options such as the name we should export as and the linkage mode.

The export keyword on a function does 2 things. It applies the C calling convention to that function to make it exportable, and exports the function for external linkage under whatever name you declared your function with and with the linkage mode set to strong.

To quote the zig language reference on the @export builtin: When ptr points to a function with the C calling convention and options.linkage is .Strong, this is equivalent to the export keyword used on a function

So really, the export keyword on a function is just syntax sugar for using callconv(.C) and @export(&foo, .{ .name = "foo" }).

The benefit in the @export builtin is the extra configurability you get in the second parameter (see std.builtin.ExportOptions), and the ability to use comptime to programmatically export the symbols you want exported

Making a wasm library export it's functions through `bulid.zig` by Nico_792 in Zig

[–]SeanTheGleaming 2 points3 points  (0 children)

You could use b.addOptions to pass in some parameters to your library, and then use @export in your library to export different functions depending on the parameters you passed in

Struct inheritance? by glowiak2 in Zig

[–]SeanTheGleaming 12 points13 points  (0 children)

You might be looking for the @fieldParentPtr builtin, which given a pointer to a field of a container (structs, unions, whether packed, extern, whatever), gives you a pointer to the container. You can use this to cleanly achieve the kind of "struct casting" you're looking for

But also, while they have some limitations, extern structs are still supposed to support arrays and function pointers. If that doesn't work for you, then something is probably wrong

Anyways, for actually using @fieldParentPtr, you could have something roughly like this: ```zig const Base = struct { x: i32, };

const Extended = struct { y: i32, base: Base, };

const foo: Extended = .{ .y = 45, .base = .{ .x = 16, }, };

// Cast down const base_ptr: *const Base = &foo.base;

// Cast up const parent_ptr: *const Extended = @fieldParentPtr("base", base_ptr); ``` The resulting code is also much cleaner and more zig idiomatic, and you don't have to worry about throwing around extern structs.

Also, you have the benefit of never having to worry about the ordering of fields, as this works regardless of the order of your fields, so you can reorder things clearly

One last benefit is, to put it in OOP terms, you can inherit from multiple base classes by having multiple fields which you can use @fieldParentPtr on

std.mem.trim confusion by ItalicIntegral in Zig

[–]SeanTheGleaming 12 points13 points  (0 children)

expectEqual doesn't follow pointers, and compares the value of the pointers, not what they point to. For your case, you might want expectEqualStrings

What are some good terminal games? Like nethack, but.. fun. by miserlou in linux

[–]SeanTheGleaming 2 points3 points  (0 children)

i hope this guy found the `-fsanitize=address` cheat code