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/
<Tetralux> Oh - if you're returning ?[]u8, you can just do `else |err| return null;` for example.
<via> still, even if i make the return type !void, i get: error: expected optional type, found '@typeOf(std.fmt.bufPrint).ReturnType.ErrorSet![]u8'
<via> if (std.fmt.bufPrint(buf[0..], "rpm: {}\n", c_tfi.config.decoder.rpm)) |slice| {
<Tetralux> Yeah I get that too when I try to do it here... but the example I showed you from the stdlib works fine.
<Tetralux> Maybe I'm just blind, but I'm not seeing what's different there xD
<via> well, the else is handled in your example
<Tetralux> If that was the problem I'd expect it to say "error not handled" etc.
<Tetralux> That smells like a bug to me.
<via> if i add else |err} { return; } it works fine
darithorn has joined #zig
<Tetralux> Hmmm.
<Tetralux> Maybe. I guess that's just a bad error message then.
<Tetralux> But yeah - if you don't wanna handle the error in the fn, normally you'd use `try std.fmt.bufPrint(...)` or catch unreachable.
<Tetralux> (.. though of course, that's asserting that it shouldn't ever fail.)
<Tetralux> (.. which if it's hacky code, or you're first pass at writing the code anyway..) :)
<Tetralux> Though you don't have to, but I'd suggest opening an issue about that error message.
<Tetralux> I know that'd trip me up.
<Tetralux> You can also do `else |_|` to mark that you don't care about the error, as well, by the way - rather than naming it anything.
<via> so i made the function return type !void and now have const slice = try std.fmt.bufPrint(buf[0..], "rpm: {}\n", c_tfi.config.decoder.rpm);
<via> but in my toplevel (c, returning c_int) function, try myfunc() catch return 0; errors
<Tetralux> 'try' means "if this errors, return it from this fn"
<Tetralux> You don't use it as 'try ... catch ...'
<Tetralux> It'd just be myfunc() catch return 0.
<via> ah, so erroneous try. catch works fine
<via> okay, thank you, sorry for dumb questions
<Tetralux> All good ;p
<Tetralux> catch means "if this errors, do this instead; if not, just unwrap the success value"
<via> yep
<Tetralux> whereas try is "if this errors, return the error; if not unwrap the success value."
<Tetralux> i.e: try x() == x() catch |err| return err
<via> makes sense
<Tetralux> Marvellousness :)
fengb has quit [Ping timeout: 260 seconds]
<via> fmt combined with the slice/buffered streams in io is awesome -- compared to my c version which uses repeated sprintf's and hopeful/careful management of a pointer
fengb has joined #zig
fengb has quit [Ping timeout: 260 seconds]
diltsman has joined #zig
<diltsman> On head, how do I get my build.zig to build release mode?
<diltsman> Huh...help seems to indicate --release-fast while -Drelease-fast appears to work.
<Tetralux> I believe that's right. -Drelease-fast etc.
<Tetralux> The help should be more clear if that's the case though.
<Tetralux> That does seem a little inconsistent.
<diltsman> I know that this isn't Zig, but any idea how to get rid of lld: error: no memory region specified for section '.ARM.exidx'?
<diltsman> I have this in my .ld file: .ARM :
<diltsman> {
<diltsman> . = ALIGN(4);
<diltsman> *(.ARM.exidx);
<diltsman> }>flash0
<diltsman> If I do "zig.exe build", then it works. "zig.exe build -Drelease-fast" fails.
<diltsman> Do I have to do anything in my build.zig to point release and debug builds to the same linker script?
darithorn has quit [Quit: Leaving]
<andrewrk> diltsman, do you have reason to believe they're getting different linker scripts?
<andrewrk> you can pass --verbose to `zig build` to see the args it's passing
daurnimator has joined #zig
<diltsman> PS Z:\Zig\SAM3X8E> Z:\Zig\zig-windows-x86_64-0.4.0+ae2345b7\zig.exe build --verbose
<diltsman> cp Z:\Zig\SAM3X8E\zig-cache\o\9juUm81eIZNrHpCKw0-BVTGGARYltPNJoHEQ3bHMZ6iiHoyJX7LS1Oj90vIgYlRl\SAM3X8E Z:\Zig\SAM3X8E\zig-cache\bin\SAM3X8E
<diltsman> PS Z:\Zig\SAM3X8E>
<diltsman> I deleted zig-cache first.
<diltsman> -Drelease-fast: Z:\Zig\zig-windows-x86_64-0.4.0+ae2345b7\zig.exe build-exe Z:\Zig\SAM3X8E\test.zig --release-fast --cache-dir Z:\Zig\SAM3X8E\zig-cache --name SAM3X8E -target armv7m-freestanding-eabi --linker-script Z:\Zig\SAM3X8E\build.ld --cache on
<andrewrk> yeah so that's getting the linker script
<diltsman> No flag: Z:\Zig\zig-windows-x86_64-0.4.0+ae2345b7\zig.exe build-exe Z:\Zig\SAM3X8E\test.zig --cache-dir Z:\Zig\SAM3X8E\zig-cache --name SAM3X8E -target armv7m-freestanding-eabi --linker-script Z:\Zig\SAM3X8E\build.ld --cache on
<diltsman> The only difference between the two is --release-fast
<andrewrk> that's expected
fengb has joined #zig
<andrewrk> so the differences you are observing must be due to optimizations
<diltsman> If I comment out the section where I place .ARM.exidx then the debug one fails with the same error.
fengb67 has joined #zig
<diltsman> Time to start looking at objdump and readelf.
fengb has quit [Remote host closed the connection]
<mikdusan> try `.ARM.exidx*`
<diltsman> That fixed it. What is the reason?
<mikdusan> honestly gon't know. it was just some google-fu
<diltsman> Thanks.
<andrewrk> might be worth a bug report to LLD
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #zig
<diltsman> I need to look into exactly what the .o files contain. It is possible that they are doing something slightly different that lld then correctly pukes on.
fengb67 has quit [Ping timeout: 260 seconds]
<daurnimator> andrewrk: could you have a look into fixing #2850 ?
_whitelogger has joined #zig
<andrewrk> daurnimator, yes
_whitelogger has joined #zig
fengb has joined #zig
darithorn has joined #zig
darithorn has quit [Quit: Leaving]
fengb has quit [Ping timeout: 260 seconds]
diltsman has quit [Ping timeout: 260 seconds]
hio has joined #zig
qazo has quit [Ping timeout: 268 seconds]
iamthad has quit [Quit: ZNC - https://znc.in]
iamthad has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
kristoff_it has joined #zig
iamthad has quit [Ping timeout: 264 seconds]
iamthad has joined #zig
iamthad has quit [Ping timeout: 250 seconds]
iamthad has joined #zig
DutchGhost has joined #zig
iamthad_ has joined #zig
iamthad has quit [Ping timeout: 258 seconds]
<DutchGhost> Is it bad to get a segfault trough a ptrcast at comptime?
<samtebbs> DutchGhost: Code example?
<DutchGhost> Aaaanddd I crashed llvm
<DutchGhost> lol
<samtebbs> lel
<samtebbs> issue time
<DutchGhost> yeah
iamthad_ has quit [Ping timeout: 272 seconds]
iamthad has joined #zig
torque has quit [Ping timeout: 252 seconds]
torque has joined #zig
DutchGhost has quit [Ping timeout: 272 seconds]
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #zig
Tetralux has quit [Ping timeout: 245 seconds]
Tetralux has joined #zig
nifker has joined #zig
nifker was kicked from #zig by ChanServ [Banned: disrespect !T 1w]
DutchGhost has joined #zig
bugabinga has joined #zig
DutchGhost has quit [Ping timeout: 248 seconds]
dimenus has quit [Ping timeout: 268 seconds]
dimenus has joined #zig
dimenus has quit [Ping timeout: 246 seconds]
DutchGhost has joined #zig
DutchGhost has quit [Remote host closed the connection]
fubd has joined #zig
<fubd> comptime question. how would I make a "registry" of types? i.e., I want to define a Foo struct, and call "registerType(Foo)" at compile time, and have at compile time an array of all the types
<scientes> how do i cast bool to u8?
<scientes> do i have to use a comparison?
<scientes> for u8(bool)
<scientes> /home/shawn/git/zig-simd/build/y.zig:4:10: error: expected type 'u8', found 'bool'
<scientes> and with @bitCast return @bitCast(u8, ((v == x) == @Vector(4, bool)([4]bool{ false, false, true, false})).all);
<scientes> error: destination type 'u8' has 8 bits but source type 'bool' has 1 bits
<scientes> so i have to use a comparison to cast from bool?
<scientes> that seems a bit verbose.....
<scientes> @bootToInt()
<scientes> *boolToInt
<mq32> has anyone started an imaging library for Zig already?
<mq32> so: loading, manipulating and saving image files?
<scientes> I think tgschultz has a libpng library
<scientes> mq32, you can always use C
<mq32> scientes, this question was more about: "is it worth to start writing a general purpose imaging library for zig?"
<mq32> i could use some comptime image loading stuff
<scientes> if it is fun for you, yes
<scientes> the language has stabilized a lot, but there still will probably be some changes you will have to adapt your work to
<mq32> yeah, i'm fully aware of that
<mq32> but i am kinda desperatly searching for a better way to build my embedded projects than having a cluster of small, very different programs that prepare resources for me
<scientes> well yeah comptime is great
<mq32> i have like, 10 precompilers for different resources that just prepare binaries
<mq32> and zig allows to do that *in language* and *in program*
<mq32> even just
<scientes> and it works now
<mq32> const my_blob = @embedFile("is_wow");
<mq32> and if I do the image processing library right, i can do stuff like this:
<mq32> const background_texture = Image.load(@embedFile("my_source.png").palettize(16);
<mq32> which would create a comptime palettized image :)
diltsman has joined #zig
fengb has joined #zig
DutchGhost has joined #zig
DutchGhost has quit [Ping timeout: 246 seconds]
<fubd> my second failed attempt at a comptime type regsitry: https://gist.github.com/kevinw/3088dbf4ac849c0e42f9549f2387abf3
<scientes> mq32, you mean a bitmap?
<scientes> palettized bitmap
<scientes> or in that case a 16-bit bitmap
<scientes> unpalettized
<scientes> cause if you are using a pallet you probably should have the ability to specify the pallet
<mq32> scientes, yeah, bitmap
<mq32> in my primary use case i don't have shared palettes, but this is a thing
<mq32> probably i would start coding a bit, then writing a specification of what i want on features and then start the library design…
<scientes> also huffman code stuff for JPEGs
<mq32> oh, yeah
<daurnimator> and deflate for PNG
<scientes> mozilla made a good library for that
<scientes> to losslessly optimize JPEG huffman codes
<scientes> how do i know if a type is const in the compiler?
<samtebbs> fubd: It's probably because your registery is `var`
<fubd> samtebbs: if it's const, I get an error because I'm trying to assign to it
halosghost has joined #zig
fubd has quit [Remote host closed the connection]
<samtebbs> fubd: Have you tried using an ArrayList to store the types?
<mq32> samtebbs: wasn't there an issue about "making stuff comptime mutable, but runtime immutable"?
<samtebbs> mq32: Perhaps, I haven't seen it. That would be cool
<scientes> how do i know if the target of a pointer is comptime?
DutchGhost has joined #zig
<DutchGhost> what do you think of a module-global allocator?
desperek has joined #zig
<fengb> Only if it's replaceable
<DutchGhost> `const s = @import("module.zig").init_module(&allocator.allocator);`
<mq32> what would "module-global allocator" mean in this context?
Akuli has joined #zig
<desperek> hi, how can i link to a library on windows? all i get is "lld: error: undefined symbol: SDL_Init" so far :/
<DutchGhost> This is module.zig: https://pastebin.com/91adwvGk
<DutchGhost> this is main.zig: https://pastebin.com/t8Num6b0
<DutchGhost> see how the `mod_alloc` is replacable, but yet global to the module
<fengb> Looks okay but thread problems >_>
<DutchGhost> why thread problems?
<fengb> Swapping out halfway through
<DutchGhost> Not if the collections take in the allocator
<fengb> Usually in cases like this, I'd prefer using a context struct
bugabinga has quit [Quit: Connection closed for inactivity]
<fengb> Example: two thread try to use different arena allocators. This is global so one of them just swapped allocators underneath the entire program
<DutchGhost> if any struct that needs an allocator copies the module's global allocator (its just a ptr, so copy is cheap), then it doesnt matter if you change the allocator halfway trough
<DutchGhost> except top level the allocator must still be in mem ofc :3
<DutchGhost> which is why still every struct and function using allocation should have its own version of the global alloc ptr
<DutchGhost> it just copies when created
<DutchGhost> then you dont have this "ohh but someone swapped underneath me"
<fengb> Uhhh allocator pointers are the same reference. You currently can't copy allocators
<fengb> tgschultz has a branch that changes that
<DutchGhost> notice the mod_alloc is a `*std.mem.Allocator`
<fengb> Oh I see
<DutchGhost> I mean it kinda 'solves' the thing of passing allocators to everything, if you wrap it like this?
<fengb> Honestly, I don't think passing allocators should be solved
<scientes> ugggh, i really find it annoying that i have to wrap values into pointers to the stack in the compiler
<DutchGhost> no but it's annoying when you continuously have to pass in the same allocator to everything
<scientes> oh there are some helpers to that
<fengb> Either there's a top level entrypoint, in which case you can copy the allocator there. Or there's not an entrypoint, in which case it's better for consuming libraries to pass in allocators
<mq32> DutchGhost: Last week andrew showed us @import("root") which imports is a reference to your root level file. so you could potentially do `@import("root").allocator`
<fengb> Like in your code, I can't just put the vector in an arena easily.
<DutchGhost> but then a module has to assume the top-level attribute is called `allocator`, @mq
<mq32> yes, that's correct ;)
<DutchGhost> and so what if it thinks its called `alloc`?
<mq32> but as fengb said: if you write a library, don't make global stuff and if you write a program, it's a safe assumption
<DutchGhost> and another module assumes its called `allocator`?
<DutchGhost> you could @fengb, just set the mod's allocator to an arena allocator, and make a new Vec
<tgschultz> that's why we pass allocators. the alternative is a default global allocator that everything calls on and then you have all the same problems other languages have because of that
very-mediocre has joined #zig
dimenus has joined #zig
<desperek> "lld: error: could not open SDL2: is a directory" duh
ntgg has quit [Quit: leaving]
<desperek> how do i link it if it doesnt work that way?
bheads has quit [Ping timeout: 248 seconds]
<desperek> oh ok it works when i add .lib, nvm
<desperek> why does it work like that though?
very-mediocre has quit [Read error: Connection reset by peer]
very-mediocre has joined #zig
<mq32> desperek, i assume because windows usually links with file name whereas unixoids link with "library name"
<desperek> oh well
<desperek> mq32, does it link statically with the linkSystemLibrary?
<mq32> i really have to do some more stuff with zig just for the sake of learning the language... :(
<mq32> dunno, i'm just into the language theory right now, haven't done much projects with zig yet
<desperek> i see
<desperek> thanks
bheads has joined #zig
<fengb> I remember loving everything I read about Rust... then I used it >_>
<bheads> I have been thinking lately that signed integer types should be prefixed with s and not i.
<DutchGhost> why?
<mq32> fengb, yeah, i made that mistake too ^^
<bheads> we have uXX for unsigned so sXX for signed makes more sense
<mq32> i noticed that my small single-file-services take up 600 MB of storage in the build cache
<mq32> O.o
<bheads> i32 is a C holder over
<fengb> It's also in LLVM and Rust
<very-mediocre> integers are expected to be able to be negative
<bheads> was teaching someone new to programing
<very-mediocre> unsigned integers are a specialized integer
<DutchGhost> whats wrong with Rust fengb?
<mq32> bheads, i think i32 is more clear as it is more widespread
<bheads> it just added an extra layer
<very-mediocre> i32 makes more sense, it's literally just an integer
<mikdusan> s32 looks like 4-byte utf
<fengb> DutchGhost: nothing *wrong* with it. It's just a lot of overhead to get stuff done that I can't really grok
<bheads> it was just a though it terms of teaching
<DutchGhost> overhead? mmhh
<desperek> oh yeah i feel very similar i think fengb
<fengb> There's 3 different string types, macros for error handling, result types, borrow checker, etc.
<desperek> although i know a person who likes rust
<DutchGhost> macro's for error handling? whoa
<fengb> try is a macro
<mq32> there's a lot of macro stuff going on
<DutchGhost> we had `try!`
<DutchGhost> now its `?`
darithorn has joined #zig
<mq32> the main thing Rust had for me was this (already) huge library
<fengb> I think Rust is great to replace C++. But I'm not a C++ guy for a reason :P
<desperek> i feel like i would have to read the whole rust book to get any grasp of it
<DutchGhost> there's multiple string types, altough you only use `String` and `&str` regularly
<fengb> Yeah it's just conceptually big
<bheads> D went crazy with the string types too
<bheads> string wstring dstring char wchar dchar
<fengb> Again, I'm not saying Rust isn't good. I just couldn't get into it
<DutchGhost> and it makes sense, `String` == `Vec<u8>`, while `&str` == `&[u8]`. Its just not that hard when you see it like that
<DutchGhost> one is owned, the other is a view into an owned thing
<very-mediocre> imho the biggest annoyance of Rust is lifetime annotations
<mq32> yeah, but then you don't need two types, just use Vec<u8>
<DutchGhost> No. Passing a slice is cheaper
<mq32> DutchGhost, i meant "String" vs. "Vec<u8>"
<fengb> Anyway... I stuck with zig because I could basically dive right in while fixing a lot of my problems with C
<DutchGhost> `Vec<u8>` doesnt provide utf-8 safety
<mq32> yeah, but really? substring doesn't do, either ^^
<DutchGhost> substring?
<DutchGhost> whats substring?
<mq32> why have substring if you do it on code units (string slicing)
<DutchGhost> what do you mean by substring?
<DutchGhost> the `&str` thing?
<mq32> and if you accidentally index a half code point, everything explodes
<DutchGhost> You cant index half into a code point
<mq32> you can
<mq32> but it will panic
<andrewrk> the space for rust & zig to exist is pretty clear: zig gains simplicity in exchange for moving memory safety to be a runtime concern
<mq32> as String does code unit indexing, not code point indexing
<andrewrk> zig's release-safe build mode is slower than rust's release mode
<mq32> andrewrk, yeah, i think so too. Both languages have their purpose and their predecessors
<companion_cube> I'd love Zig to be standardized and become part of big compiler distributions when it reaches 1.0, too
<fengb> Just a random aside: what do game devs think of Zig or Rust?
<companion_cube> something rust will have more trouble doing
<andrewrk> zig also have finer grained safety; if you're writing a lot of unsafe code, or code that has a mix of safe and unsafe, I think zig is more safe than rust (in which you would have to use `unsafe` blocks)
<DutchGhost> And I think that having a dedicated String type is just easier to get stuff done when working with strings. When I use strings, I dont want to go into this 'but its a Vec of bytes' thing and like push raw bytes or whatever
<andrewrk> DutchGhost, what are you working on that needs a decoded string?
<very-mediocre> DutchGhost: you can always make one in userland
<mq32> andrewrk: I like that Zig doesn't use that much of abstractions but is pretty close to LLVM/Hardware without sacrificing this for security
<mq32> that's the reason i probably won't switch over to Rust in most of my projects because a lot of stuff is considered "unsafe"
<andrewrk> DutchGhost, if you decode strings unnecessarily, it's needlessly opening a can of bugs
<DutchGhost> atm nothing andrewrk. yes I know you could very-mediocre. But then you gotta first build it, but that costs time and energy, so then for a little use-case you're not going to
<andrewrk> I think it's actually an important design decision whether or not you will need to decode strings, that you should figure out somewhat early on
<mq32> got to go
<DutchGhost> because well, it just is easier for a little usecase to just go back to a vec of bytes
<andrewrk> that requires a heavy dependency to get right (the unicode data libraries)
ffddr has joined #zig
<companion_cube> if you just need a codec you don't need heavy data, do you?
<companion_cube> utf8 is reasonably easy to decode
<companion_cube> it's for normalization/modifications/classifications that it becomes complicated
<andrewrk> right but why decode it if you don't need to understand the codepoints in any meaningful way? might as well have left it encoded
<andrewrk> if you're just re-encoding it in a different way, for example UTF-16LE to call windows APIs, you don't need a String type
<companion_cube> decode means you can validate it, at least
<companion_cube> that's what `str` means in rust: it's valid utf8, is all (and you can iterate on codepoints)
<andrewrk> yes - I would argue the best way to do that would be to call validate() on an encoded byte buffer though
<andrewrk> hm I see, so getting the type system to participate in whether it's valid. that has merit
<companion_cube> that'd be a `[]u8 -> str` function :)
<companion_cube> rust also has an unsafe version of that where you promise it's actually valid, without runtime check
<DutchGhost> Im not saying a `String` type should be part of the std. I am saying that I think it's easier to reason about a `String` then a `Vec of bytes`, and most people know what a `String` is, while they dont always know how its represented below, so know they see vectors of bytes all over the place and they dont know what is going on.
<fengb> I think this is another case where a distinct typealias would be handy
<companion_cube> but yeah, a `str` is valid utf8 and that's a good invariant to have
<ffddr> Hi! Is there any way to introduce a struct field based on some comptime condition?
<andrewrk> ffddr, short answer: no
<andrewrk> ffddr, if I'm guessing your use case correctly, there's another way to do it which should be OK
<desperek> is there some tutorial about what's an allocator and all btw?
<andrewrk> the field modification_count: debug_u32, // will be void sometimes or u32 other times
<andrewrk> void fields do not have any code generated for them
DutchGhost has quit [Remote host closed the connection]
<andrewrk> desperek, did you see the Memory section of the language reference yet? https://ziglang.org/documentation/master/#Memory
<dimenus> before I open an issue, I wanted to have a quick discussion about Windows. It seems that Zig generates def/lib files even when linking to libc
<ffddr> andrewrk I see, thank you! actually I did not have any particular use case yet, just validating my understending of comptime expressions in structs.
<dimenus> and this is causing issues with both the libc hello world example and the windows example
<desperek> yeah but i kinda still fail to see why would i use it but thats for another field i guess, andrewrk
<very-mediocre> desperek: it's for dynamic memory, think "new" in C++
<very-mediocre> in zig you bring your own "new"
<andrewrk> desperek, if you don't need heap memory, then don't use heap memory. you'll know when you discover you need it
<desperek> right. thanks.
ffddr has quit [Remote host closed the connection]
<andrewrk> generally you will run into a problem that needs solving with heap memory when the amount of memory you need to use for something is only known at runtime
<andrewrk> you can't put that memory on the stack because, how would you know how big a stack you would need?
<companion_cube> andrewrk: about the `{x; y}` syntax for blocks returning expressions, wouldn't the current warnings on unused values be sufficient to make very clear the distinction between `{x; y;}` (void) and `{x; y}` (same value as y)?
ffddr has joined #zig
AlexMax has quit [Ping timeout: 250 seconds]
darithorn has quit [Quit: Leaving]
<very-mediocre> I don't think this is the case, but would a compiler be smart enough to optimize an array of bools into an int?
<very-mediocre> ...i guess i will just write this utility function
<samtebbs> very-mediocre: I know that GCC can do that under certain optimisatio levels
<samtebbs> Not sure about LLVM
<very-mediocre> I see
<very-mediocre> I know very little about esoteric optimizations
<very-mediocre> oh, i see someone wrote a packed int array in stdlib
<very-mediocre> that'll work with some u1
<samtebbs> very-mediocre: Oh nice :)
<samtebbs> andrewrk: I've been building a z80 computer on and off for a while now, and would love to write some code for it in Zig. Do you know if having z80 as a target in Zig is realistic?
very-mediocre has quit [Read error: Connection reset by peer]
<samtebbs> There is a fork of llvm with a z80 backend
very-mediocre1 has joined #zig
very-mediocre1 is now known as very-mediocre
<andrewrk> samtebbs, I do want zig to be able to support a wide range of targets, even wider than what LLVM supports. that's a couple years out though. if you want to make progress on that now, what that looks like is maintaining a fork of zig that uses that fork of llvm with the extra backend
<andrewrk> I'm happy to help if you decide to do such a project
<andrewrk> help meaning answer questions if you run into trouble
desperek has quit [Quit: mew wew]
<samtebbs> andrewrk: That does sound like the best option right now, at least until mainline llvm gets a z80 backend (if ever xD)
<samtebbs> Thanks
<samtebbs> I'll add that to the long list of things to investigate :)
<samtebbs> I think helping with arm and aarch64 support in Zig is my priority
<samtebbs> I'm going to see if work will allow me to use some of our native hardware to test things on, I can't guarantee it though
<andrewrk> great :)
samtebbs has quit [Quit: Leaving work, will check back in later]
qazo has joined #zig
fengb has quit [Remote host closed the connection]
<donpdonp> z80++ i was just watching Ben Eater's youtube vids of building an 8bit cpu from TTL chips
<Tetralux> (Reposting from last night) This isn't the correct error is it? https://paste.gg/p/anonymous/826d705ca39c46928886c3df217c3332/files/589458846be144198ea93c92ea1da701/raw
<dimenus> woo fix'd
kristoff_it has quit [Ping timeout: 246 seconds]
very-mediocre has quit [Read error: Connection reset by peer]
very-mediocre1 has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
<Tetralux> If it was because of not handling the error, surely it should say that.
<very-mediocre1> you have to use try
<very-mediocre1> without try, it returns SomeErrorset![]u8
<very-mediocre1> also you're using `if` in a way that tries to unwrap the expression in the parentheses (optional type -> unwraps to something if it isn't null)
<Tetralux> If works with errors, because it you use `else |err|` it works fine.
<very-mediocre1> - std.fmt.bufPrint has a return type of ![]u8 so you have to handle the error as you correctly identified, after doing so you're left with a []u8 instead of ![]u8
<very-mediocre1> - you can't do if([]u8)
<very-mediocre1> hm oh yeah
<very-mediocre1> ok i see your point
<mikdusan> Tetralux: yeah nice errors like "did you mean to do `else |err|` is probably stuff that will come in with stage2 compiler
<very-mediocre1> Tetralux: i totally misunderstood your example, you're right
<very-mediocre1> indeed the docs say "// The else and |err| capture is strictly required."
<Tetralux> It should say "error not handled"
<Tetralux> There isn't an optional here...
ffddr has quit [Remote host closed the connection]
tankf33der has joined #zig
<tankf33der> o/
<tankf33der> i want to read a two numbers from stdin and print to stdout every number increased by 1.
<tankf33der> can somebody write me this program on zig? i know, really strange request.
darithorn has joined #zig
HesamR has joined #zig
HesamR has quit [Remote host closed the connection]
<tankf33der> i see
<Tetralux> Once you do that, you can call .read on it.
<Tetralux> If you want to read binary data, you can call .inStream() which has things like .readIntLittle.
very-mediocre1 has quit [Read error: Connection reset by peer]
very-mediocre has joined #zig
<Tetralux> If you want to read text, you can call .read or .inStream and .readFull etc, etc.
<Tetralux> Is anyone else not able to build release stage1 on Linux?
diltsman has quit [Remote host closed the connection]
HesamR has joined #zig
FireFox317 has joined #zig
<FireFox317> You mean building zig with cmake -DCMAKE_BUILD_TYPE=Release?
<FireFox317> For me that works fine
<Tetralux> I'm on Manjaro Arch and there's https://github.com/ziglang/zig/issues/67
<Tetralux> Which seems... unhelpful xD
<FireFox317> I'm on 'raw' Arch and I can build it succesfull, however I do use local checkouts of LLVM and clang. Maybe this issue is helpfull: #2340
jjido has joined #zig
<very-mediocre> took me way too long because of handling \r\n on windows, then realizing std.io has functions that handle it :)
<tankf33der> no chance. thanks a lot
<very-mediocre> updated slightly #ocd
Akuli has quit [Quit: Leaving]
FireFox317 has quit [Remote host closed the connection]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Tetralux> ??? xD
very-mediocre has quit [Read error: Connection reset by peer]
jjido has joined #zig
very-mediocre1 has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qazo has quit [Read error: Connection reset by peer]
qazo has joined #zig
diltsman has joined #zig
diltsman has quit [Read error: Connection reset by peer]
qazo has quit [Read error: Connection reset by peer]
diltsman has joined #zig
qazo has joined #zig
<tankf33der> how correctly import std and math to use like:
<tankf33der> var a = try Int.initSet(al, 123);
<tankf33der> ?
<tankf33der> stuck with compilation, as usual.
<Tetralux> const std = @import("std");
<Tetralux> (.. Same for math.)
<mq32> you can just alias everything with const
<mq32> const Int = std.math.Int; // (if this exists)
<Tetralux> You can also `use @import("std")` if you'd prefer.
<Tetralux> Though that's not common.
very-mediocre1 has left #zig [#zig]
<Tetralux> It's done this way so that where symbols come from is very obvious and you don't have to guess.
<tankf33der> i didnt use zig for years and stuck somewhere between 0.1 and 0.2
<tankf33der> versions.
<dimenus> think of const as let in other languages
<dimenus> it's just a name
<tankf33der> no chance.
jjido has joined #zig
jjido has quit [Client Quit]
<dimenus> tankf33der: it's Int.initSet not big.initSet
<tankf33der> i see
HesamR has quit [Read error: Connection reset by peer]
<dimenus> most zig files have tests right in the file themselves. You can check there for usage.
jjido has joined #zig
jjido has quit [Client Quit]
andersfr has joined #zig
<tankf33der> home/mpech/tankfeeder/bigtest/bigint.z:10:16: error: use of undeclared identifier 'Int'
<tankf33der> var a = try Int.initSet(al, 0x123);
<tankf33der> ^
<tankf33der> dimenus: ^^^
<Tetralux> FireFox317: Ta btw :p
<Tetralux> Hoepfully I can fix it without building LLVM myself...
<Tetralux> I really don't wanna do that.
<dimenus> tankf33der, you can either 'use big' to import the fullnamespace or 'const Int = big.Int'
<dimenus> tankf33der, have you looked at any of the examples? eg: https://github.com/ziglang/zig/blob/master/example/cat/main.zig
<tankf33der> :)
brett-soric has joined #zig
andersfr has quit []
xvb has joined #zig
jjido has joined #zig
xvb has quit [Ping timeout: 272 seconds]
halosghost has quit [Quit: WeeChat 2.5]
brett-soric has left #zig [#zig]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<andrewrk> anyone want to do a fun zig API that the stage1 compiler can use?
<andrewrk> I'll type up an isseu
<Tetralux> Whatcha thnking?
ltriant has joined #zig
dimenus has quit [Quit: Leaving]
fengb has joined #zig
dimenus has joined #zig
<Tetralux> How would this interact with other console output?
<Tetralux> Or is the idea to just not have any xD
<andrewrk> what other console output?
<Tetralux> This is a thing that's just in the compiler?
<dimenus> i understand that this may be a non-standard task, but is there a quick way to initialize a large struct to 0s?
<dimenus> memset?
<hryx> dimenus: you can also provide default values in struct definitions now
<dimenus> hryx: do you have a quick example? doesn't seem to be in the documentation
<dimenus> apologies :(
<andrewrk> no worries
<dimenus> on the plus side, I used Zig at work and fixed linking with libc on Windows
<hryx> wow! zig comes to the workplace
<dimenus> idk how that test has been passing until now
<dimenus> not formally, I just actually have downtime at the moment. So I'm exploring the feasibility of using it for backend stuff
<fengb> andrewrk: could we infer struct field types via default values?
<andrewrk> hmm, that would make sense syntactically, wouldn't it? I think it's worth a proposal.
<Tetralux> That can be handy if it's not a outward-facing struct, or if the answer is obvious - like a bool field for instance.
<fengb> I'll write one up
<hryx> nice idea fengb
<andrewrk> ok so I know I was supposed to be working on pull requests today
<dimenus> *drumroll*
<andrewrk> but instead I have a branch with zig able to cross compile targeting windows, with a fully operational libc
<andrewrk> I just cross compiled SDL2 on linux for windows
<andrewrk> with out of the box zig
<dimenus> system libc?\
<dimenus> or zig's implementation?
<andrewrk> it's mingw-w64
<dimenus> ah
<dimenus> that's excellent though
<andrewrk> so this becomes the new libc-capable target list: https://clbin.com/0e7Ty
<andrewrk> technically the ABI would be gnu not msvc but they *are* ABI-compatible. I'm still thinking about how to deal with that
<dimenus> wait, full blown cygwin or mingw64?
<andrewrk> anything that builds with mingw-w64 builds with this
<dimenus> nice
<andrewrk> it adds about 59 MiB in installation size to zig (7 MiB to the tarball size)
<dimenus> I think my next goal is going to be to clean up / finalize MSVC detection on windows
<dimenus> it's picking up 2017 instead of 2019 on my machine
<andrewrk> well here's the thing
<dimenus> 2015 is not worth the effort
<andrewrk> maybe we can simply delete MSVC detection and stop caring about MSVC's existence
<dimenus> mingw's libc is hacky IIRC
<dimenus> we still need msvc detection for kernel32 et al
<dimenus> that doens't go away
<andrewrk> what we need is a really good counter example, of why we need msvc integration
<andrewrk> nope, zig provides kernel32 et all in this branch
<dimenus> not when you link a c library on windows
<dimenus> i ran into fat bugs when doing that
<dimenus> (which is what my PR is about)
<andrewrk> that's just a problem with polluting the current working directory
<dimenus> we generate def/libs for what is called in Zig, not what hte library calls
<andrewrk> and not specifying full paths to lib files
<dimenus> but we do still need the detection?
<andrewrk> this branch has full blown kernel32 & friends
<dimenus> that's how we get the full path to kernel32
<shachaf> Man, Windows sounds like a complicated platform to compile for.
<dimenus> you don't know the half of it :P
<shachaf> Why do you need kernel32 to compile?
<andrewrk> kernel32 is essentially the stable syscall API on Windows
<shachaf> Do you mean the .dll or the .lib?
kristoff_it has joined #zig
<shachaf> I'm trying to figure out how things work. It looks like mingw can link directly to a .dll but I'm probably confused about things.
<dimenus> on windows, you don't directly link with a dll
<dimenus> you link with an import library
<dimenus> or a static library
<shachaf> "The cygwin/mingw ports of ld support the direct linking, including data symbols, to a dll without the usage of any import libraries."
<andrewrk> kernel32.lib is an "import library" which is just setting up to dynamically load kernel32.dll
<shachaf> Maybe this is just some random thing that doesn't actually work well, though.
<andrewrk> mingw is not to be confused with mingw-w64, which is a fork
<andrewrk> mingw-w64 supports i386, x86_64, 32-bit arm, and 64-bit arm
<andrewrk> I don't know why anyone uses mingw anymore
kristoff_it has quit [Ping timeout: 245 seconds]
<shachaf> It sounds like mingw64 can do it too?
fengb has quit [Ping timeout: 260 seconds]
FireFox317 has joined #zig
<FireFox317> Nice work andrewrk! I do want to note that there is a security vulnerability with ASLR or something, probably good to keep in mind or to write down for sure
<emekankurumeh[m]> dimenus what kind of errors are you getting?
darithorn has quit [Quit: Leaving]
<emekankurumeh[m]> andrewrk: does zig compile without a dependency on libwinpthread?
<andrewrk> yeah I didn't do anything with libwinpthread