ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
steveno has joined #zig
porky11 has quit [Ping timeout: 268 seconds]
suirad has quit [Ping timeout: 256 seconds]
suirad has joined #zig
<daurnimator> andrewrk: what is your view on aliasing?
<daurnimator> andrewrk: have you though about no-alias by default?
<daurnimator> +t
* daurnimator thought about it while reading https://news.ycombinator.com/item?id=18543371
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
SimonN has joined #zig
SimonNa has quit [Ping timeout: 250 seconds]
<suirad> ive always enjoyed how aliasing and stuff works in ponylang
ibebrett has joined #zig
steveno has quit [Remote host closed the connection]
<ibebrett> question about the allocator code
<ibebrett> however the allocFn "inner function"
<ibebrett> does not assume that parameter is comptime
<ibebrett> is there a reason why it couldn't? It would help me with using a "child allocator" as an implementation for a debug checking allocator i'd like to create
ibebrett has quit [Ping timeout: 256 seconds]
<suirad> ibebrett: i made something similar if you need a hand
ibebrett has joined #zig
<ibebrett> thanks, I'd like to take a look
<ibebrett> tanks
m6w6 has quit [Quit: ZNC - http://znc.in]
m6w6 has joined #zig
m6w6 has quit [Ping timeout: 264 seconds]
m6w6 has joined #zig
jjido has joined #zig
ibebrett has quit [Ping timeout: 256 seconds]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
wink_ has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
wink_ has joined #zig
forgot-password has joined #zig
<forgot-password> Hi :)
forgot-password has quit [Quit: leaving]
porky11 has joined #zig
forgot-password has joined #zig
davr0s has joined #zig
Hejsil has joined #zig
<Hejsil> forgot-password, Yo
<forgot-password> Hey :) I'm currently playing around with OpenGL in zig, but the glShaderSource function is giving me a few problems.
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<forgot-password> I have a source string of type `[]const u8` and glShaderSource has the signature /Users/hannes/Documents/playground/zig-test/hello.zig:52:29: error: expected type 'type', found 'extern fn(u32, i32
<forgot-password> , ?[*]const ?[*]const u8, ?[*]const i32) void'
<forgot-password> Oops, sorry for that fuck-up ^^
<forgot-password> And I'm not sure how the get a [*]const [*]const u8 from my source string. I at least got it compile with @ptrCast(const[*] const[*]const u8, &vsrc.ptr), where vsrc is my shader source. It also doesn't crash at runtime, but it doesn't seem like the way to go :p
<Hejsil> Well, [*]const [*]const u8 smells a lot like a 2 dim array. Sure this argument is suppose to just point to 1 string?
<Hejsil> "Specifies an array of pointers to strings containing the source code to be loaded into the shader."
<forgot-password> No it can actually take an array of strings
<forgot-password> Wait if I do &vsrc.ptr don't I have a pointer to a pointer to a char, which is basically a two-dimensional array of chars or an array of strings?
<Hejsil> That is true. Sadly @typeOf(&vsrc.ptr) will be *const [*]const u8
<forgot-password> Thank you, will get back to you soon :)
<forgot-password> Is the `c"a"` saying that it should be interpreted as a single character and not a string?
davr0s has joined #zig
<Hejsil> No, it a c string literal. It gives you a null terminated string
<Hejsil> Which you'll most likely need when calling into C :)
<forgot-password> Ohh, that's how I do that... Does it work for multiline strings?
<Hejsil> Yes, just append c to all lines
<Hejsil> c\\
<forgot-password> Sorry if I'm bothering you with such basic questions, but the langref.html isn't the most complete documentation I know of :P
<forgot-password> Would I have to import strlen/build it myself in order to get the length of a c string or is there a std function? Because I can't find any
<Hejsil> There is std.cstr.len and mem.len (they do the same).
<Hejsil> mem.len is the generic implementation for getting the length of any null terminated array
<Hejsil> Ops, sorry. I just read this comment on cstr.len: "Deprecated, use mem.len"
<Hejsil> mem.len it is
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<daurnimator> Hejsil: I'm not sure why that exists TBH
<daurnimator> I feel like mem.indexOf(x, '0'); would be more self explanatory
davr0s has joined #zig
<forgot-password> Hi, it's me again. I just created a gist where I commented a few lines I need help with. Thanks in advance to anybody who takes a look at it :)
<forgot-password> Here's the link to the gist: https://gist.github.com/schroffl/ff86ed745533b7eb6df13f2832c4bea2
<Hejsil> daurnimator, well indexOf only works on slices, so it is always safe and returns ?usize
<Hejsil> mem.len works on unknown length points, is unsafe and returns usize
<Hejsil> Maybe mem.indexOfAny is better, as then you can have any termination you want
<Hejsil> forgot-password. the logLength question is related to this issue: https://github.com/ziglang/zig/issues/1059
<Hejsil> Currently, you could do @ptrCast([*]u32, &logLength) instead of declaring the array, but it feels pretty bad to do ptr casts
<Hejsil> As for allocators
<MajorLag> If you have an idea the maximum size that you care about for the log, you can just create a static buffer and pass that directly without an allocator: `var staticMemory: [max_size]u8 = undefined;` `c.glShaderInfoLog(shader, std.math.min(logLength, max_size), null, &staticMemory);`. If you'd rather dynamically allocate to ensure you can get the entire log: `var direct_allocator = std.hea.DirectAllocator.init(); var allocator = &direct_alloca
<MajorLag> tor.allocator; var allocatedMemory = allocator.alloc(u8, logLength); c.glShaderInfoLog(shader, logLength, null, allocatedMemory);`
<MajorLag> there may need to be a pointer cast in there, I've not had to interface with C for a while.
<MajorLag> Oh, and you'll probably want to free that memory at some point `defer allocator.free(allocatedMemory);` will ensure it is freed at scope exit.
<Hejsil> Well, was making an example, but you summed it up
steveno has joined #zig
<forgot-password> Thank you very much, that helps me a lot :)
<forgot-password> MajorLag, do I need to initialize staticMemory? I updated the gist from earlier (the function of concern is `getShaderInfoLog`) if you want to take a look at it. I'm currently working on a Mac and OpenGL support was deprecated by Apple earlier this year, so I'm not sure whether my problems are caused by that or if they happen due to my code. The latter is obviously much more likely
<MajorLag> Your buffer can't be const, because you're going to modify it.
<MajorLag> also you can't return it as a slice, since it is on the stack, it isn't valid outside the scope of the function.
<forgot-password> I see, that makes sense
<MajorLag> Two options: move the buffer to the global scope (and make it var) and return a slice of it, or dynamically allocate it, in which case you'll need the allocator to be declared and initialized in the global scope and you'll need to free the memory later.
<forgot-password> Wouldn't passing the allocator as an argument be a lot cleaner? Or is that not possible?
<Hejsil> That is the recommended way to do allocations (passing allocators around)
<forgot-password> I'm gonna keep it global for now... I can still do some cleanup when I got it to work ^^
<forgot-password> Alright, now I can get the log, but when I try to log it via `warn` it crashes with “unreachable code“. If I put a `warn` after my `c.glGetShaderInfoLog`-call it still gets written, so I'm guessing that's not the problem
<MajorLag> Does it say which line number and file the unreachable is in?
<MajorLag> And yes, typically allocators are passed in as the first parameter to functions that need them. You'd still have to declare the allocator itself globally so that it is in scope for the duration of the allocation's lifetime.
<MajorLag> Well, or in main
<MajorLag> ` @ptrCast([*]u8, &buffer)` allocator.alloc returns a slice, so you don't want `&buffer` here since buffer is already a pointer. You don't even need `@ptrCast` here, you can do `buffer.ptr` to get the `[*]u8` prat of the slice.
<forgot-password> Oh, that actually caused the crash... It works now :)
<Hejsil> Hmmm. I wounder if we should structure the interface in std like this instead: https://gist.github.com/Hejsil/442d8fa0c4c715b4b6f9db29f96a1684
<forgot-password> Is a std.heap.DirectAllocator not a subset of std.mem.Allocator?
Hejsil has quit [Quit: Page closed]
<MajorLag> std.heap.DirectAllocator is an implementation of the std.mem.Allocator interface. The actuall interface is the `.allocator` part of the initilaized DirectAllocator instance.
<MajorLag> `var allocator = &direct_allocator.allocator;` <= allocator is of type *std.mem.Allocator.
<MajorLag> `direct_allocator` is of type std.heap.DirectAllocator.
qazo has quit [Ping timeout: 250 seconds]
Hejsil has joined #zig
<forgot-password> Thank you everybody, the code now works without a problem :)
<forgot-password> I was just looking into Vulkan and look what I found here: https://github.com/andrewrk/zig-vulkan-triangle, heh ^^
Zaab1t has joined #zig
ducktype has quit [Quit: Page closed]
Hejsil has quit [Ping timeout: 256 seconds]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
wilsonk has quit [Read error: Connection reset by peer]
wilsonk has joined #zig
forgot-password has quit [Quit: Lost terminal]
oconnor0 has joined #zig
steveno has quit [Ping timeout: 268 seconds]
davr0s has joined #zig
porky11 has quit [Ping timeout: 268 seconds]
steveno has joined #zig
wootehfoot has joined #zig
jjido has joined #zig
jjido has quit [Ping timeout: 250 seconds]
jjido has joined #zig
adrusi has quit [Ping timeout: 252 seconds]
adrusi has joined #zig
d_s has joined #zig
jjido has quit [Read error: No route to host]
jjido has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
vegecode has joined #zig
vegecode has quit [Client Quit]
Zaab1t has quit [Quit: bye bye friends]
davr0s has joined #zig
jjido has quit [Read error: Connection reset by peer]
steveno has quit [Remote host closed the connection]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
jjido has joined #zig
davr0s has joined #zig
jjido_ has joined #zig
oconnor0 has quit [Quit: Page closed]
wootehfoot has quit [Read error: Connection reset by peer]
jjido_ has quit [Quit: Textual IRC Client: www.textualapp.com]
jjido has quit [Read error: Connection reset by peer]
jjido has joined #zig
jjido has quit [Remote host closed the connection]