ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
smolck has left #zig [#zig]
_Vi has quit [Ping timeout: 244 seconds]
radgeRayden has joined #zig
ur5us has quit [Ping timeout: 246 seconds]
haliucinas has quit [Read error: Connection reset by peer]
haliucinas has joined #zig
g_w1 has joined #zig
<g_w1> test
<g_w1> is this working
ur5us has joined #zig
<klltkr> g_w1: you're coming through loud and clear
<g_w1> cool. my first time on irc
cr1901_modern has left #zig [#zig]
nephele_ has joined #zig
nephele has quit [Ping timeout: 272 seconds]
nephele_ is now known as nephele
zippoh has quit [Ping timeout: 258 seconds]
decentpenguin has quit [Quit: ZNC crashed or something]
marnix has joined #zig
marnix has quit [Ping timeout: 258 seconds]
klltkr has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cole-h has joined #zig
smolck has joined #zig
<smolck> is there a way to get the value of a nested anonymous struct, i.e. given .{false, .{5, 6, 7}} get the .{5, 6, 7} and iterate over it?
<smolck> if I try and access it by @typeInfo(@TypeOf(...)).Struct.fields[1].default_value (in this case) it just returns null
<daurnimator> smolck: anonymous structs are made to be coerced to something.
<daurnimator> smolck: but also, anonymous structs are I think comptime fields?
<daurnimator> not default values.
<smolck> hmm
<smolck> I guess I'm trying to use them like arrays that can take any type of value
<smolck> which is not such a good idea?
<daurnimator> they'll coerce to arrays....
<daurnimator> but note that you'll have trouble using them at runtime
<daurnimator> e.g. your `5` there is of type `comptime_int` -> you need to coerce it into a runtime type for it to exist at runtime
<smolck> yeah I've noticed that, which can be a bit annoying
<smolck> but interestingly, the way I have things set up currently, all I have to do is add `comptime` to the start of the nested struct and it works
<smolck> one unrelated question I have though, is there a way to coerce something like "hello" to []const u8 w/out an @as cast or similar?
<daurnimator> just assign it to a variable of type []const u8
<daurnimator> const foo: []const u8 = "hello";
<smolck> sorry, should have clarified, I mean within a struct, so have it be that type in this sort of situation: .{"hello"}
<smolck> hmm
<daurnimator> no. @as *is* the way to do that
<daurnimator> anything else would be contrived....
<smolck> yeah okay
<smolck> that makes sense
<smolck> cool, thank you for your help!
smolck has left #zig [#zig]
marnix has joined #zig
ur5us has quit [Ping timeout: 256 seconds]
xd1le has quit [Read error: Connection reset by peer]
xd1le has joined #zig
frett27_ has joined #zig
frett27_ has quit [Ping timeout: 240 seconds]
a_chou has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
ur5us has joined #zig
a_chou has quit [Quit: a_chou]
ur5us has quit [Ping timeout: 265 seconds]
marnix has quit [Ping timeout: 258 seconds]
marnix has joined #zig
omglasers2 has joined #zig
jjsullivan1 has joined #zig
cole-h has quit [Quit: Goodbye]
<jjsullivan1> hi, I have a question about zig's compile-time evaluation. Would it be possible to modify an array of structs at compile time? I'm making a virtual keyboard, and I'd like to precalculate the approximate position of each key in a layout based on how wide the key is. I tried writing this down as far as I could here https://gist.github.com/jjsullivan5196/a8f923473f923e7f4d31a6d03c05b14a
<jjsullivan1> I left ellipses for the declarations I couldn't figure out, of course idk if this method is idiomatic/correct in zig
st4ll1 has joined #zig
radgeRayden has quit [Read error: Connection reset by peer]
<daurnimator> jjsullivan1: take in a `[]Key`, and then you'll probably need to declare that array as a `comptime var` and take address of it?
<jjsullivan1> daurnimator: ahhh, I didn't realize there was a `comptime var`. I think I was digging in the wrong parts of the manual. I'll give that a try, thank you!
marnix has quit [Read error: Connection reset by peer]
_Vi has joined #zig
<daurnimator> jjsullivan1: https://godbolt.org/z/hKEzdn
marnix has joined #zig
<daurnimator> jjsullivan1: actually... you don't even need the `comptime` keywords! https://godbolt.org/z/snxY5d
<jjsullivan1> daurnimator: thank you! it makes more sense now
<daurnimator> jjsullivan1: so you making a QMK replacement? :)
<daurnimator> funnily enough I was thinking about the same thing today
<jjsullivan1> I'm not sure what QMK is, but there's a lack of easy-to-hack on screen keyboards for wayland. So I started working on one in C
<daurnimator> ah. QMK is a firmware for actual hardware keyboards
<jjsullivan1> but there's a few things like this that would be helped by compile-time eval. So, I'm seeing if zig can help me out
<daurnimator> QMK is written in C and uses a unreadable series of macros to let you configure your keyboard at compile time
<daurnimator> I was looking at https://git.sr.ht/~technomancy/menelaus for inspiration
<jjsullivan1> yeah, there's some similar problems I'm trying to get around
<jjsullivan1> first I got a simple surface example working in wayland, then I tried porting some of sxmo-svkbd over https://git.sr.ht/~mil/sxmo-svkbd
<jjsullivan1> and while it is a 'simple' program, I think a few parts of it could be expressed more easily with explicit ctfe and other tricks
<daurnimator> jjsullivan1: one application I can imagine is typing my password into a bootloader
<daurnimator> for tablets and 2-in-1s I don't know of any UEFI password entry systems
<jjsullivan1> the guys at postmarketOS have that covered, they made one that uses the linux framebuffer
<jjsullivan1> it uses SDL_Renderer though, so it can only blit to the framebuffer or open as a desktop window
<daurnimator> I'm talking about in a pre-boot environment
<daurnimator> zig can target UEFI :)
<jjsullivan1> oh yeah, I'll keep that in mind actually
<jjsullivan1> The drawing library I use only needs pixman, and pixman can probably run in a stripped down environment
<jjsullivan1> might not even need it to begin with, pretty sure it's only doing some fancy buffer fills I could do on my own. It does give me a nice frontend to freetype though:^(
<daurnimator> jjsullivan1: freetype? why not harfbuzz directly?
<jjsullivan1> the more you know :^)
<jjsullivan1> I wasn't even using freetype directly, it's just what pixman was using
<jjsullivan1> or this drawing library itself, guess that's more reason to drop it
<jjsullivan1> wayland can just hand me memory mapped buffers to barf pixels on, probably easier to do simple fills + harfbuzz
<jjsullivan1> the real dragon though is fontconfig
<jjsullivan1> god help me
<daurnimator> fontconfig? do you need to touch that?
<jjsullivan1> to search installed fonts yeah, there's probably an alternative but I haven't looked into it
<jjsullivan1> maybe I should just skip attribute-based searches for fonts, but most people expect to just give fontconfig pattern strings for most stuff
<jjsullivan1> for a UEFI environment or something like that I'd definitely skip it and pack in a font file
ur5us has joined #zig
* Michcioperz whispers "const font = @embedFile(…)"
_Vi has quit [Ping timeout: 246 seconds]
dec05eba has quit [Remote host closed the connection]
xd1le has quit [Read error: Connection reset by peer]
xd1le has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
_Vi has joined #zig
_Vi has quit [Ping timeout: 246 seconds]
marnix has quit [Ping timeout: 246 seconds]
marnix has joined #zig
knebulae has quit [Read error: Connection reset by peer]
knebulae has joined #zig
Snetry has quit [Ping timeout: 264 seconds]
Snetry has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
_Vi has joined #zig
klltkr has joined #zig
martylake_ has joined #zig
klltkr has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
klltkr has joined #zig
marnix has quit [Ping timeout: 265 seconds]
marnix has joined #zig
waleee-cl has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
klltkr has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Snetry> It seems to be that someone has created a Wiki entry just advertising themselves https://github.com/ziglang/zig/wiki/TA
<ifreund> I sent them an email and deleted it
<ifreund> wanted to paste a link to the community page in the commit message deleting it, but github didn't give me a chance
<ifreund> and well, looks like the mail bounced
<Snetry> weird
marnix has quit [Ping timeout: 256 seconds]
marnix has joined #zig
xackus has joined #zig
sqwishy has quit [Read error: Connection reset by peer]
sqwishy has joined #zig
klltkr has joined #zig
_Vi has quit [Ping timeout: 246 seconds]
martylake_ has quit [Ping timeout: 245 seconds]
isolier has quit [Ping timeout: 260 seconds]
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
brotein has joined #zig
<brotein> hi
<brotein> I successfully built zig from source! After leaving yesterday on some linking errors
<Nypsie[m]> What was the culprit?
<brotein> that's because I only built llvm but not lld,clang from source so there was a version mismatch
<Nypsie[m]> Aaaah I see
<brotein> it's actually a bit treacherous from llvm
<brotein> you need to pass to cmake the option: -DLLVM_ENABLE_PROJECTS="clang;lld"
<brotein> otherwise they are disabled by default
<brotein> and of course I had installed clang and lld to be able to build llvm, through the package manager, thus with a different version
<brotein> so kind of a dumb oversight from me
<Nypsie[m]> Made me check our docs to see if this is written down, fortunately it is:
<brotein> Right, I had a look at the instructions on the wiki but they differ from the ones on the llvm project
<brotein> which I favored
<Nypsie[m]> Aah good to know
<brotein> I feel it is simpler to follow the llvm instructions where you clone the git repository and you only do cmake; make;
<brotein> with the right cmake options of course
<brotein> and you are on the right git tag, e.g v10.0.0
<brotein> For the curious, the exact commands are:
<brotein> git checkout llvmorg-10.0.0.0
<brotein> mkdir build; cd build
<brotein> cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="AVR" -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_PROJECTS="clang;lld"
<brotein> make ; sudo make install
<brotein> anyways thanks for the help I got here!
brotein has quit [Remote host closed the connection]
brotein has joined #zig
dmiller has joined #zig
<dmiller> Hello! Is there a function similar to `readUntilDelimiterOrEof` for reading from stdin, except it just reads until EOF rather than also accepting a delimiter? Thanks!
a_chou has joined #zig
whatupdave has joined #zig
dmiller is now known as dmiller2
dmiller has joined #zig
whatupdave has quit [Client Quit]
_Vi has joined #zig
dmiller2 has quit [Remote host closed the connection]
a_chou has quit [Quit: a_chou]
Akuli has joined #zig
<traviss__> dmiller, have you tried read(buffer: []u8) or readAll(bufer: []u8) ?
cole-h has joined #zig
riba has joined #zig
klltkr has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<KoljaKube> It is not possible to initialize single elements of an array that is a struct member with default values, right? :-/
riba has quit [Ping timeout: 265 seconds]
riba has joined #zig
riba has quit [Ping timeout: 265 seconds]
brotein has quit [Remote host closed the connection]
klltkr has joined #zig
<ifreund> KoljaKube: sure it is: [1]u8{42} ++ [1]u8{undefined} ** 5;
<ifreund> then you get an array of length 6 with the first value initialized to 42 and the rest undefined
<KoljaKube> My member is `.content: [some_const][some_other_const]?[]u8 = std.mem.zeroes([come_const][some_other_const]?[]u8`
<KoljaKube> I had hoped for something like `.content[0][0] = only_element_set`
<KoljaKube> I would have preferred having the rest of the array filled by the default defined in the struct
_Vi has quit [Ping timeout: 260 seconds]
<KoljaKube> But that would take two steps I guess
<KoljaKube> I'm using an initializer block now, repeating the mem.zeroes in there. That way I at least don't need to calculate array sizes
dongcarl has quit [K-Lined]
marijnfs has joined #zig
radgeRayden has joined #zig
<marijnfs> I see the allocator.zig now defines the class directly in the zig file? How does this work
<KoljaKube> Every file is implicitely a struct as well, or am I misunderstanding the question?
<marijnfs> no that was what i was wondering
frett27_ has joined #zig
<marijnfs> it that new?
<KoljaKube> No
<alexnask[m]> Its been a while
<marijnfs> it's a bit jarring the first time, but also interesting
<KoljaKube> It saves you from having to usingnamespace or `const MyStruct = @import("my_struct").MyStruct;`
<marijnfs> yeah I found that annoying as well. So thats cool
<KoljaKube> Someone also linked to river's source (on reddit I think?), where the same is in use: https://github.com/ifreund/river/blob/dd425a3e6622c0a2df704bb8b629b58e882d4ce2/river/View.zig
<KoljaKube> I had to look twice too ;-)
<marijnfs> yeah mentally I expect to see a struct and some indentation
nvmd has joined #zig
<KoljaKube> Yeah, I was surprised about all those global variables :D
<ifreund> I really like not having everything in the file indented an extra level
<ifreund> I think I was one of the earlier adopters
<ifreund> but yeah this has been a thing since before 0.6.0
<KoljaKube> It was definitely there before I found Zig
<KoljaKube> That extra level wouldn't be so bad if Zig used only two spaces for indentation >:)
<KoljaKube> I love that the Zig documentation page has a auto-switching dark mode. Delights me every time it switches while I work with it
<ifreund> oh I use darkreader so I never noticed
<marijnfs> don't start indentation wars:P
<marijnfs> also, tabs are better than spaces
<ifreund> well, yeah but consistency wins
<Nypsie[m]> Good thing we don't have this in stage 2 :P
marijnfs_ has joined #zig
<andrewrk> the new css media query for dark mode is very much in line with "Communicate intent precisely" :)
<andrewrk> when you do that right, the user doesn't have to interact at all, things Just Work
marijnfs has quit [Ping timeout: 260 seconds]
sqwishy has quit [Read error: Connection reset by peer]
sqwishy has joined #zig
wootehfoot has joined #zig
nvmd has quit [Quit: Later nerds.]
marnix has quit [Ping timeout: 240 seconds]
marnix has joined #zig
marnix has quit [Ping timeout: 264 seconds]
davi2205 has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
ur5us has joined #zig
<andrewrk> argh, I can't repro this llvm11 failure using only llvm/clang
<andrewrk> nvm got it
Michcioperz has quit [Read error: Connection reset by peer]
Michcioperz has joined #zig
Akuli has quit [Quit: Leaving]
<davi2205> Hello! I have a question, is it safe to cast fn(*A)void to fn(*u8)void? (A is any non zero bit type)
<fengb> Only with a well defined calling convention
<fengb> e.g. callconv(.C)
<davi2205> I'm willing to store callbacks in an ArrayList like struct { target: *u8, func: fn(*u8)void }
<davi2205> const CallbackEntry = struct { target: *u8, func: fn(*u8)void };
<davi2205> target is a pointer to any sized struct that was previously cast to *u8
<davi2205> I'm not sure if that's a good strategy tho
<marijnfs_> I guess alignment can be an issue?
<davi2205> It apparently works, but I don't know whether I'm just lucky
<marijnfs_> so in the callback you cast back to the datatype you want?
<alexnask[m]> `*@Type(.Opaque)` is usually used for this kind of type erasure
<alexnask[m]> Since it represents a type with unknown size
<marijnfs_> i'm trying to parse that
<alexnask[m]> `const CallbackEntry = struct { pub const Erased = @Type(.Opaque); ctx: *Erased, func: fn (*Erased) void }`
<marijnfs_> I would suggest he just casts to u8 like a human being
<davi2205> marijnfs, I implement the callback function using the target type like fn myCallback(self: *A) void
<alexnask[m]> Why? This is the same generated code but clearer, `*u8` is a single item pointer to a u8, `*Erased` is a single item pointer to an item of unknown length
<marijnfs_> I guess just don't call it Erased
<davi2205> then I call the callback function using the CallbackEntry struct like entry.func.*(entry.target);
<marijnfs_> that's very confusign
<alexnask[m]> But anyway, suit yourself, just mentioning how Ive seen other zig codebases do this
<marijnfs_> yeah it's probably the most proper way to do it
<marijnfs_> but a *u8 also says it doesn't know the length right?
<marijnfs_> it's not a []u8
<alexnask[m]> And yes Erased is prob bad, Context or something is probably better
<alexnask[m]> No, `*u8` is a single item pointer, I guess you could use `[*]u8` (which is a pointer to an unknow number of elements)
<marijnfs_> ah yes
<davi2205> I'll try the @Type(.Opaque) method
<marijnfs_> where does .Opaque come from?
jjsullivan1 has quit [Remote host closed the connection]
<alexnask[m]> .Opaque is an enum literal, @Type takes std.builtin.TypeInfo which is a union(enum) with `Opaque: void`
<alexnask[m]> Because the payload is void, .Opaque will coerce to TypeInfo
<marijnfs_> ah okay @Type takes the enum as argument, and .Opaque is an element therein
xackus has quit [Ping timeout: 265 seconds]
mokafolio has quit [Quit: Bye Bye!]
<Nypsie[m]> Hell yeah, zlib/deflate in std!
mokafolio has joined #zig
omglasers2 has quit [Read error: Connection reset by peer]
<davi2205> well, it crashed the compiler lol
jmiven has quit [Quit: reboot]
jmiven has joined #zig
davi2205 has quit [Ping timeout: 246 seconds]