dddddd has quit [Remote host closed the connection]
seoushi has joined #zig
<seoushi>
So in c I used void pointers for generics/structs of any type. So in zig I can do ArrayList(*void) which works but I'm not sure that is the best option. The ArrayList doesn't know all the possible types it will contain. Is this still a "good" practice or is there a feature I'm missing out on?
<daurnimator>
seoushi: see the allocator interface for how you might do that
<seoushi>
I know how to do it. I'm just wondering if there is something better that I'm missing out on
<seoushi>
or if that is pattern in zig a well
qazo has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
return0e has quit [Ping timeout: 265 seconds]
return0e has joined #zig
metaleap has joined #zig
ltriant has quit [Ping timeout: 265 seconds]
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen1 has joined #zig
dingenskirchen1 is now known as dingenskirchen
seoushi has quit [Ping timeout: 265 seconds]
_Vi has joined #zig
chrisb has left #zig [#zig]
metaleap has quit [Quit: Leaving]
meraymond2 has joined #zig
meraymond2 has quit [Remote host closed the connection]
_Vi has quit [Ping timeout: 272 seconds]
ur5us has joined #zig
return0e_ has joined #zig
<Snektron>
seoushi, you could consider @OpaqueType(), or a union/tagged union if you know all types beforehand
qazo_ has joined #zig
qazo has quit [Ping timeout: 268 seconds]
qazo_ has quit [Ping timeout: 240 seconds]
qazo has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
_Vi has joined #zig
qazo has quit [Ping timeout: 265 seconds]
return0e_ has quit [Remote host closed the connection]
return0e_ has joined #zig
ltriant has joined #zig
ltriant has quit [Ping timeout: 260 seconds]
<betawaffle>
i sorta wish there was a way i could constrain a function to not allow certain things, like stack usage.
<betawaffle>
i also wish i could explicitly define a calling convention, forcing it to put arguments/return values in specific places
<mq32>
custom calling convention?
<mq32>
or just enforce a default one?
<mq32>
hm
<mq32>
sadly, my experiments with zig and godot are failing
<mq32>
code compiles, but it will segfault at a place inside the engine i cannot locate
<betawaffle>
mq32: custom, like being able to specify that my entrypoint function is called with arguments in registers X and Y
<mq32>
so yeah, custom calling convention
<betawaffle>
as an alternative to a "naked" function with inline asm that reads those registers into local variables
<betawaffle>
(which incidentally may be spilled to stack, if i'm not careful)
<betawaffle>
basically it'd be nice to be able to be confident in writing more things without asm
decentpenguin has joined #zig
<mq32>
problem with calling conventions is that the code gets forced to a certain CPU arch
<mq32>
zig code is pretty much CPU agnostic atm
<betawaffle>
right, but it has all kinds of comptime things that make it feasible to tweak things, rather than right multiple implementations
mattmurr has left #zig ["User left"]
mattmurr has joined #zig
ltriant has joined #zig
mahmudov has joined #zig
<mq32>
gruebite, i found another problem with Godot
ltriant has quit [Ping timeout: 265 seconds]
BaroqueLarouche has joined #zig
<mq32>
huh
<mq32>
zig has problems with following C abi when passing structs?!
<dimenus>
andrewrk: can i ask you a quick libsoundio question?
unrahul2 has joined #zig
BaroqueLarouche has quit [Quit: Connection closed for inactivity]
unrahul has quit [Ping timeout: 260 seconds]
BaroqueLarouche has joined #zig
unrahul2 has quit [Ping timeout: 260 seconds]
<andrewrk>
dimenus, sure
<dimenus>
maybe it's not a libsoundio issue (i'm a newbie when it comes to this), but essentially i'm expecting the audio to be interleaved as LRLRLR, but ultimately the only solution that's working is to pull down as many bytes as if the stream was stereo
<daurnimator>
dimenus: btw, libsndfile is brilliant as a C library. Might want to use that for all your codec support?
<dimenus>
daurnimator: thanks for the tip, i'm using libmpg123 atm
Akuli has quit [Quit: Leaving]
<daurnimator>
dimenus: that's still required for mp3
<dimenus>
ah got it. i probably wouldn't use mp3 on things I build myself, this is just to finish up my breakout clone (https://learnopengl.com)
<dimenus>
i'm almost done, just have text/audio to do
metaleap has joined #zig
<dimenus>
andrewrk: I actually think I'm overwriting past where I should be in libsoundio
<andrewrk>
dimenus, I think you can set the requested layout
<dimenus>
in libmpg123 or soundio?
<andrewrk>
dimenus, in libsoundio, set the layout field of your output stream before calling soundio_outstream_open
<andrewrk>
dimenus, as for interleaved, the soundio API hides that from you with the "areas" struct
<dimenus>
i get that, which is why it feels like my code SHOULDN'T work
<andrewrk>
look carefully at how the examples use the SoundIoChannelArea struct. it abstracts away interleaved/separate channels
<dimenus>
although, the step on the area is 4 bytes not 2
marmotini_ has joined #zig
<dimenus>
andrewrk: I don't understand what you mean by hides it from me with the areas struct?
<dimenus>
Are you saying that I can pass the same stream into all areas if it's interleaved and it will just work?
<andrewrk>
if you do the math like it's done in the examples, with `areas[channel].ptr + areas[channel].step * frame` then it will work regardless of whether the layout is interleaved or planar
<dimenus>
ah, yeah that's what i missed. I thought step would be two bytes so i just casted the ptr to an [*]i16 instead of [*]align(4) i16
<dimenus>
thanks
marmotini_ has quit [Ping timeout: 268 seconds]
<dimenus>
andrewrk: thanks, looping over works as expected now. Apologies for thinking I could ignore the example and just straight copy into the buffer. I now see that the two pointers are returned are only two bytes appart - so my situation just happened to work by happy accident
<andrewrk>
no worries. it's a bit confusing
<andrewrk>
that was the simplest abstraction I could come up with to handle all the different sound systems
<dimenus>
i was trying to straight copy because i thought it would be faster, but if I can just set a non-default layout to do that
<dimenus>
this also explains why i was getting so much static / garbage when I tried to implement it this way before (but without mapping the step)
<dimenus>
because I was mapping samples two bytes out instead of 4
mahmudov has quit [Ping timeout: 265 seconds]
marmotini_ has joined #zig
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
mahmudov has joined #zig
<metaleap>
using `builtin.TypeInfo` stuff: AFAICT whenever at least one arg of multiple in an `fn` is `var`, the `FnArg.arg_type` seems `null` for *all* args of the corresponding `Fn` descriptor.
<metaleap>
just to confirm: is that always the case or are there exceptions?
ltriant has joined #zig
<metaleap>
also cannot take such a func's address?! is that true or did i get a confused compiler msg..
_Vi has quit [Ping timeout: 252 seconds]
lunamn has joined #zig
lunamn_ has quit [Ping timeout: 265 seconds]
<SyrupThinker>
metaleap: Well whats the message?
<metaleap>
already gone, but sth like "cannot take addr of size-0 type"
<metaleap>
only for ptrToInt of an fn with a `var` arg, when reverting to fully-typed no prob of course. wasnt a big need for var there tho, just had to try while at it
marijnfs has joined #zig
<SyrupThinker>
Well I'd say thats a case of unhelpful compiler error
lunamn has quit [Read error: Connection reset by peer]
<SyrupThinker>
Should probably say something like "cannot take address of var function"
<metaleap>
it comes up for different situations, so would guess these situations all end up at the one code path
<metaleap>
that raises it
<metaleap>
probably going to need carrying-contextual-details-along logic in there sooner or later
<metaleap>
for more differentiated msgs
<fengb>
Ah yeah generic functions aren’t “real”. You’ll need to wrap it if you want to make a function pointer
lunamn has joined #zig
<SyrupThinker>
Which mentions something I just wanted to point out :)