AceNovo has quit [Remote host closed the connection]
<DonnieWest[m]>
Silly question here from a zig/C newbie. I'm trying to call this function zig-side https://github.com/graphql/libgraphqlparser/blob/master/c/GraphQLParser.h#L29-L30. The type of that in zig seems to be [*c][*c]const u8 . I'm missing how to create a corresponding zig variable to pass in of that type to hold the error. Anyone know what to do there?
<DonnieWest[m]>
And perhaps more importantly, where could I read up on that?
jayschwa has joined #zig
a_chou has joined #zig
<ryuukk_>
does anyone have good examples how to do interface? this is confusing
<jayschwa>
DonnieWest: I'm just guessing, but have you tried something like this: var err: [*c]u8 = 0; the_function(text, &err);
<DonnieWest[m]>
jayschwa: that does the trick. Thanks!
<ryuukk_>
i don't understand how can this be called "interface"
xackus_ has joined #zig
xackus has quit [Ping timeout: 256 seconds]
<ryuukk_>
i feel like something zig is auto limiting itself to not add new syntax, the result to solve common problems become an unreadable and unmanageable mess
<ryuukk_>
sometimes*
<justin_smith>
ryuukk_: how do you define interface?
<ryuukk_>
i would have expected to be as simple as GO at least
<justin_smith>
so "how can this be called interface" wasn't a question, it was a complaint?
<justin_smith>
well "how do you define interface?" "I expect something simpler" - I have no follow up for that
radgeRayden has quit [Quit: No Ping reply in 180 seconds.]
<ryuukk_>
that is what i expect from modern language, go or rust type interface
<ryuukk_>
not all that confusing code in the zig interface link above
<ryuukk_>
it just asks for bugs and hard to maintain code
radgeRayden has joined #zig
<ryuukk_>
just like enum, i expect something in the same vein for interfaces
<ryuukk_>
it feels like inconsistent, on one hand you have nice features that simplify your life, on other you do job of a compiler
<justin_smith>
if I'm reading the zig and go examples correctly, in the go example you implement the functions at the top level of the file, in the zig version the functions are inside a data structure
<ryuukk_>
i picked zig recently, maybe there are some things i don't understand and that doesn't clic yet, but it's becoming frustrating tbh
<jayschwa>
The current interface pattern is not set in stone.
<justin_smith>
jayschwa: but it's just a convention right? a struct with a member of a given name with a shared function signature
<justin_smith>
you could do the same thing in c, scheme, whatever
<ryuukk_>
no, in zig you have more code to time, duplicates, function pointers, @parentPtr thing, and u have to take the interface struct as reference from the struct
<jayschwa>
Yep. There are some issues in GitHub for potentially improving the experience by adding feature(s) to the language though.
<ryuukk_>
in go it is simple, u define the itnerface, and implement them for your struct
<ryuukk_>
easy
<ryuukk_>
what the final design will be?
<jayschwa>
It hasn't been decided as far as I know.
<ryuukk_>
i hope they take a look at GO
<ryuukk_>
interface is super common and very helpfull, i find it weird that is not something that was thought earlier and implemented as language feature
<travv0>
note that zig has generics which can fill a similar role a lot of the time
<justin_smith>
travv0: right, both are methods of late binding, an interface makes the functions a posession of the object, generics make a new object parameterized by a type plus an instance
<justin_smith>
if I understand correctly
Kingsquee has joined #zig
<ryuukk_>
it's not the same travv0
<ryuukk_>
i can't find information on interface not final desin on github
<andrewrk>
ikskuh, hm nope don't think so. this is a good week to get your project working in master with the release coming up
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
cole-h has quit [Ping timeout: 240 seconds]
<wilsonk_>
just testing a new irc client here...want to see if this statement word wraps properly. Sorry for the spam...and on a lighter note I did get a new Ryzen 3600xt system today that seems to be working nicely. Good upgrade from my old one anyways (I tend not to keep up with the cutting edge for my personal machines, because I can usually just use the servers downstairs for most things :) ).
<wilsonk_>
seems to have worked properly in the chat window and input window ;)
<omglasers2>
was thinking of getting a ryzen 3600 but the 5600x will be released next month so was thinking of waiting for it, though the 5600 would probably be a better choice if it releases
ask6155 has left #zig [#zig]
<omglasers2>
on windows with zig master I get "error: unable to detect native libc: LibCRuntimeNotFound" for ".\zig libc"; any idea why?
ask6155 has joined #zig
ask6155 has left #zig [#zig]
<ikskuh>
andrewrk: i was asking because i had a regression overnight in the cg-workbench CI
<wilsonk_>
omglasers2: just built from scratch on windows and ./bin/zig libc works fine here. Do you have to be in the build dir and not the exe dir?
nycex- has joined #zig
nycex has quit [Ping timeout: 240 seconds]
<omglasers2>
wilsonk_, well, I built zig using this https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows and "bin\zig.exe libc" gives that error, same happens with the binary from the website; I actually tried "bin\zig.exe build test -Dskip-release" initially and I got that error after some tests , so I assumed zig libc will give the same error and mentioned that
demizer has quit [Ping timeout: 258 seconds]
ask6155 has joined #zig
marnix has quit [Ping timeout: 265 seconds]
marnix has joined #zig
Kingsquee has quit []
luismanfroni has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
demizer has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
kristoff_it2 has joined #zig
_whitelogger has joined #zig
Amun_Ra has quit [Ping timeout: 256 seconds]
Amun_Ra has joined #zig
frett27_ has joined #zig
frmdstryr has joined #zig
gazler has quit [Read error: Connection reset by peer]
gazler has joined #zig
gazler_ has joined #zig
gazler_ has quit [Remote host closed the connection]
gazler has quit [Read error: Connection reset by peer]
frmdstryr has quit [Ping timeout: 260 seconds]
donniewest has joined #zig
g-w1 has quit [Ping timeout: 265 seconds]
<Michcioperz>
on 0.6.0 i can't use an array of packed enum(u2) in a packed struct, is this intentional?
<Michcioperz>
(trying to describe a microcontroller register as a volatile pointer to a packed struct)
g-w1 has joined #zig
a_chou has joined #zig
<ikskuh>
Michcioperz: you cannot use non-abi aligned types in arrays
<ikskuh>
you can use packedintarray though
<Michcioperz>
mmmmh too bad really
<Michcioperz>
last time i had this problem i just manually unrolled the array
<Michcioperz>
but that was avr and it had just 8 pins per register, this has 16 haha
<Michcioperz>
i had to blink a led in c today and it was a terrifying experience frankly
<ryuukk_>
processor.key_down.?(e.event.key_down.key); key_down is an optional, but it complains: attempt to use null value, doesn't the .? handle that case for me? or i misunderstood what .? is for ?
<ryuukk_>
i don't know how it's called, and .? is hard to google
<Michcioperz>
.? panics if value is null
<travv0>
afaik .? is like rust's .unwrap(), it'll let you use the value if it's not null, but if it is null it'll crash
<Michcioperz>
yes
<ryuukk_>
oh i see, thanks
frmdstryr has joined #zig
marnix has quit [Read error: Connection reset by peer]
<Nypsie[m]>
ryuukk_: .? is syntax sugar for `orelse unreachable`. This means in release-fast and release-small this will result in undefined behaviour. I think it will only crash in debug and release-safe.
marnix has joined #zig
<ifreund>
well, it may crash if you're lucky. The behavior is truely undefined though
<ryuukk_>
hmm
<ryuukk_>
_ = processor.key_down(e.event.key_down.key) orelse false; it complains: error: expected function, found '?fn(i32) bool'
<ryuukk_>
key_down is function that supposed to return a bool
<ryuukk_>
i'm not sure how to solve this problem
<ryuukk_>
processor is also an optional, but i handle that case already earlier
<Nypsie[m]>
Is this coming from c?
<ryuukk_>
no, it's in zig
<ifreund>
if key_down is optional you can't call it directly
<Nypsie[m]>
What's the signature of key_down? It looks like is an optional
<Nypsie[m]>
key_down is an optional function. So either call it with process.key_down.?() or `const downFn = process.key_down orelse return false; downFn(key);`
<ifreund>
you need to do e.g. `if (key_down) |kd| kd(key) else ...`
<Nypsie[m]>
Or ^
hnOsmium0001 has joined #zig
luismanfroni has quit [Remote host closed the connection]
<ikskuh>
you will break while (i < self.processing_queue_C) : (i += 1) {
<ryuukk_>
why is that??
<ikskuh>
because break will break the enclosing loop.
<ryuukk_>
i want break the switch
<dutchie>
why not just `if (processor.key_down) |key_down| key_down(e.event.key_down.key)` with no eles
<travv0>
zig switch statements don't have falltrough
<ikskuh>
give the switch a name
<ikskuh>
zig switches aren't breakable
<dutchie>
else*
<ryuukk_>
dutchie: because i have to type key_down 3 times, i don't want that
<dutchie>
so give it a shorter name
<ikskuh>
just name it "k" or "cb" or whatever
<dutchie>
if (processor.key_down) |kd| kd(e.event.key_down.key)
<travv0>
i think your goals and zigs goals are very different
<ryuukk_>
it's the same dutchie, i have to type the thing 3 times keydown kd kd
<ryuukk_>
it's noise
<ikskuh>
then write a function
<ikskuh>
which does it
<ikskuh>
call_if(key_down, .{ event.foobla });
<ikskuh>
one question:
<ikskuh>
why does your callback has a return value if you don't use it?
<ryuukk_>
i use it but not in EventQueue, the EventQueue is here to forward the events from GLFW callbacks so user can handle them properly
<ikskuh>
okay
<ryuukk_>
travv0: how can readable be against zig's readable goal?
<ikskuh>
was just wondering
<travv0>
i find zig very readable
<ikskuh>
ryuukk_: i think we have different values of readable
<ikskuh>
i dislike any operators that do more than trivial work
<ikskuh>
.? is just "access the enclosed value, ignoring the possibility of null"
<travv0>
i find terseness makes reading things harder. i have a hard time reading my own null propagation chains sometimes in c#
<ikskuh>
^= yeah, c# can get horribly unreadable in such cases
<dutchie>
ikskuh: .? is more than that imo
<ikskuh>
or even worse: linq stuff
<ikskuh>
dutchie: it isn't
<dutchie>
it's "i know this isn't null, just unwrap it"
<ikskuh>
well, kinda
<ikskuh>
it depends on your view
<ikskuh>
it's "access the value"
<ryuukk_>
"Hello, i am a humain, a humain on earth, a humain on earth with black hair", you can read it, but the intent is not "readable" repetition is noise
<ikskuh>
for release-fast/small, it will just do that and crash
<travv0>
human languages and programming languages are not comparable
<ikskuh>
ryuukk_: did you mean "hello, i am maybe a human. if i'm a human, call me bob. Bob is now doing stuff."
<ryuukk_>
ikskuh: no, null is not type, it to tell if you are here or not
<ryuukk_>
"hello, i am here, i am here on earth, i am here on hearth with black hair"
<travv0>
hello, i am human? call be bob?? i'm not real
<ikskuh>
ryuukk_: "hello, i am here, here is london, london is nice"
<ryuukk_>
Hello, is mike here? tell him to call mum or send him a message
<ikskuh>
if(condition) |declaration| usage
<ikskuh>
you are repeating the condition three times ;)
<ifreund>
I thought your goal was to "iterate quickly" but 30min later your still on the same line of code
<travv0>
dutchie: lol
<ryuukk_>
ifreund: that's what frustrate me
<ifreund>
UB!
<companion_cube>
ryuukk_: have you tried F#? I heard it's good for iterating quickly, and is terser than C# :p
<ryuukk_>
i'd stick with C# if it compiled to native and without a GC
<companion_cube>
but again, if you don't want a GC, some things become harder, at least in all the languages I've heard of
<travv0>
if you don't want a gc then you're gonna have a hard time with terseness
<ifreund>
ryuukk_: there's nothing wrong with most of the many solutions you've been shown over the past 30 min
<dutchie>
* Focus on code rather than style.
<ryuukk_>
ifreund: i know, but it makes things less readable, at least for me, wich is a problem for me
<Nypsie[m]>
Would it be possible to restructure it so `key_down` is not an optional?
<ifreund>
i suggested that 20min ago :D
<Nypsie[m]>
Ah sorry, I'm only looking now and then at the chat.
<ifreund>
ryuukk_: they don't make things less readable, incorrect code doesn't count
<travv0>
but yeah, not having the function be nullable would be the cleanest solution for sure
<ryuukk_>
ifreund: what is incorect code? having to use optionals?
<ifreund>
ryuukk_: the foo.?(key) thing you started with
<ifreund>
which I assume is what you're comparing against for readability
<ryuukk_>
my understanding of that code was: if it is not null, call it
<dutchie>
that part is correct
<ryuukk_>
the else crash is hidden
<dutchie>
no it isn't
<dutchie>
it just crashes or gives UB
<Nypsie[m]>
It's well defined :)
<ryuukk_>
foo.?(key) else false; but it doesn't work
<travv0>
and now we're back to where we started lol
<dutchie>
.? is different to c# null-coalescing
<Nypsie[m]>
Because that's syntatically incorrect
<ryuukk_>
so what's the point of having .? ?
<travv0>
i'm new to zig but i find it useful in tests
<Nypsie[m]>
Shorthand of writing `orelse unreachable`
<ryuukk_>
so i should be able to write, orelse false?
<ryuukk_>
without using .?
<travv0>
no, you can't call false
<travv0>
the function is what's optional, not the result
<Nypsie[m]>
You could read your example as `(foo orelse unreachable)(key)`
<ifreund>
the best way to do this is if (foo) |f| f() else false;
<Nypsie[m]>
^
<Nypsie[m]>
I find the structure a bit odd to be honest. You already know it's the key_down event. Why would the function be optional? (just curious btw)
<ryuukk_>
if(foo) foo(), why is that not possible?
<Nypsie[m]>
Because `foo` is still the optional, and not unwrapped
<ifreund>
how about this, instead of making the function optional have a default that always returns false
<ifreund>
then you can just call it directly
<ryuukk_>
Nypsie[m]: user can register to specific events, so i only forward if he registered to that event type
<Nypsie[m]>
Ah I see
<Nypsie[m]>
So `key_down` is a callback function, defined by the user.
<Nypsie[m]>
Got it :)
<ifreund>
so use a default that always returns false if they don't define one
<ryuukk_>
yes
<ifreund>
then you don't have to deal with the optional
<Nypsie[m]>
Yeah I think that's a great suggestion
<ryuukk_>
what do you mean a default?
<Nypsie[m]>
Define your own callback function that you set, then have it be overriden by the user's if they provide one.
<ryuukk_>
oh i see
<ryuukk_>
hmm
<ryuukk_>
yeah that could work
<ryuukk_>
i'll try and see how it goes
tane has joined #zig
donniewest has quit [Read error: Connection reset by peer]
ask6155 has left #zig [#zig]
donniewest has joined #zig
x2C25 has joined #zig
g-w1 has quit [Ping timeout: 256 seconds]
frmdstryr has quit [Remote host closed the connection]
xackus_ has joined #zig
skuzzymiglet has quit [Ping timeout: 260 seconds]
cole-h has joined #zig
frmdstryr has joined #zig
LanceThePants has quit [Read error: Connection reset by peer]
sawzall has joined #zig
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
frmdstryr has quit [Ping timeout: 240 seconds]
frmdstryr has joined #zig
frmdstryr has quit [Ping timeout: 240 seconds]
g-w1 has joined #zig
luismanfroni has quit [Remote host closed the connection]
luismanfroni has joined #zig
siulManfroni has joined #zig
luismanfroni has quit [Ping timeout: 272 seconds]
frmdstryr has joined #zig
siul_ has joined #zig
g-w1 has quit [Ping timeout: 264 seconds]
siulManfroni has quit [Ping timeout: 264 seconds]
wootehfoot has joined #zig
siul_ has quit [Remote host closed the connection]
siul_ has joined #zig
ryuukk__ has joined #zig
siul_ has quit [Ping timeout: 246 seconds]
<dutchie>
blargh, was feeling a bit low, thought i'd do something nice for the zig community and make a PR with the changes I had to make to get the sine example on the webpage working on recent compiler versions
<dutchie>
but it got merged months ago! wah
ryuukk_ has quit [Ping timeout: 240 seconds]
<dutchie>
ah well, maybe i should just go and do something that doesn't involve computers
luismanfroni has joined #zig
xackus_ has quit [Ping timeout: 256 seconds]
wilsonk_ has quit [Read error: Connection reset by peer]
xackus_ has joined #zig
moo has joined #zig
wootehfoot has quit [Ping timeout: 256 seconds]
frmdstryr has quit [Ping timeout: 260 seconds]
frmdstryr has joined #zig
frmdstryr has quit [Read error: No route to host]
frmdstryr has joined #zig
g-w1 has joined #zig
rx_ has joined #zig
skuzzymiglet has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
siulManfroni has joined #zig
luismanfroni has quit [Ping timeout: 258 seconds]
marnix has quit [Read error: Connection reset by peer]
a_chou has quit [Remote host closed the connection]
marnix has joined #zig
<ryuukk__>
hmm
<ryuukk__>
error: incompatible types: 'i32' and 'f32'
<ryuukk__>
yes, and having to do that to fix the issue
<ikskuh>
isn't really a problem if you change your code a bit
<ryuukk__>
originally it should look like as simple as this: return v > 0.0 ? 1 : (v < 0.0 ? -1 : 0);
<ikskuh>
you kinda hit the only special case
<ryuukk__>
had to convert to if else
<ryuukk__>
and now add @as
<ikskuh>
it doesn't look simple
<ikskuh>
not at all
<ikskuh>
hard to read
<ryuukk__>
@as(i32) for 1st but not all, what abou this?
<ikskuh>
you give the statement a type
<ikskuh>
which will trigger type coercion
<ryuukk__>
? : is readable
<ikskuh>
which will then make your if runtime-viable
<ikskuh>
nah, definitly not
<ryuukk__>
? is if, and : is else
<ikskuh>
your example is a perfect example for unreadable :D
<ryuukk__>
that's math
<ryuukk__>
anyways, ok for if else
<ryuukk__>
but why i has to @as the 1st and not all?
<ikskuh>
because type coercion
<ikskuh>
it makes the expression i32, not comptime_int
<ryuukk__>
why? pub inline fn sign(value: f32) i32 ask for i32, not competime_int
<ryuukk__>
if i return 1; it should be i32
<ikskuh>
doesn't work for return afaik
<ikskuh>
might be be design, might be a todo in the compiler
<ryuukk__>
if that is by design,then it is another inconfistency
<g-w1>
I think I heard this somewhere as a todo in the compiler
<ryuukk__>
how can such basic thing stay as todo?
<ikskuh>
it isn't basic
<ikskuh>
type coercion is hard
<ikskuh>
super-hard
commander has quit [Ping timeout: 256 seconds]
<ryuukk__>
if i use language, all i care about is it works as intended, naturally, people doesn't know what being the scene, if i didn't chat with you, i'd be left with a confused mind
<g-w1>
this language is not 1.0 yet
<ryuukk__>
that's valid point
<ikskuh>
you always have to keep in mind that you're still using an alpha product
<ryuukk__>
are you sure it is todo btw?
<ikskuh>
unfinished software
<g-w1>
im not sure
marnix has quit [Ping timeout: 260 seconds]
ur5us has joined #zig
commander has joined #zig
commander has quit [Remote host closed the connection]
<ryuukk__>
it took me multiple minutes to do a simple multiplication
<ikskuh>
which are all correct float-to-int conversion
<ikskuh>
which one do you want?
<ryuukk__>
so you are telling me this is not casting?
<ryuukk__>
how you would translate my c++ code above?
<ryuukk__>
in zig
<ikskuh>
i don't know ;)
ky0ko has quit [Ping timeout: 265 seconds]
<ikskuh>
it probably uses towards-zero/float truncation
<ikskuh>
which is what @floatToInt also does (it cuts of the parts after the comma)
<ryuukk__>
i have no idea, all i want is to replicate the old behavior
<ikskuh>
but is that correct for your code?
<ryuukk__>
(float) my_int
<ryuukk__>
how do you translate that from c++ to zig?
<ryuukk__>
so zig matches c++ behavior
<companion_cube>
@as(f32, my_int) I think?
<ikskuh>
@intToFloat(f32, my_int)
<ikskuh>
also, that isn't good c++ code, it's C code
<ikskuh>
c++ would be static_cast<float>(my_int)
<ryuukk__>
that is what i used, why tell me it's wrong then?
<companion_cube>
ikskuh: oops my bad
<ryuukk__>
or there is something you want to tell me that i don't understand?
<ikskuh>
ryuukk__: i'm talking about @floatToInt
<ikskuh>
so your (int)(…) code
<ryuukk__>
oh
<ryuukk__>
so how you would do (int) my_float in zig?
<ikskuh>
what rounding mode do you want? (i listed them above)
<companion_cube>
it's been answered above
<ryuukk__>
i want same behavior as the C code
<ikskuh>
okay
<ryuukk__>
it's not anwsered, he keep telling me i do the wrong thing
<ikskuh>
ryuukk__: companion_cube was talking to me
ky0ko has joined #zig
<ryuukk__>
oh ok
<ryuukk__>
so i do nothing wrong here?
<ryuukk__>
i'm confused
<ryuukk__>
there should be a @c_cast()
<ikskuh>
floating-point to integer implicit conversion and casts (always towards zero)
<ikskuh>
i found it
<ryuukk__>
so i'm not confused into picking X different things
<ikskuh>
use @floatToInt(…)
<ikskuh>
looks like it's correct
<ikskuh>
does the same as C
<ryuukk__>
ok thanks
<ikskuh>
ryuukk__: zig is about correctness. C just does a thing implicitly, but zig tells you that there might be a problem when you convert float to int
<ikskuh>
as (as explained above) the conversion is ambigious
<ikskuh>
and has four modes that can be used which might be correct in all ways
<ikskuh>
oh, there's also mathematical rounding
<ikskuh>
which rounds to the closest integer part
<ikskuh>
and if that is ambigious, rounds towards the next even number
<companion_cube>
rounding modes are such a nightmare