Bekwnn has quit [Remote host closed the connection]
daex has quit [Ping timeout: 264 seconds]
daex has joined #zig
reductum has joined #zig
dingenskirchen has joined #zig
adamkowalski has joined #zig
<adamkowalski>
do we have a trait or anything that will let me check if something is a float?
adamkowalski has quit [Quit: Lost terminal]
mokafolio has joined #zig
return0e has joined #zig
daex has quit [Ping timeout: 250 seconds]
return0e_ has quit [Ping timeout: 240 seconds]
daex has joined #zig
return0e_ has joined #zig
return0e has quit [Ping timeout: 250 seconds]
_whitelogger has joined #zig
_Vi has joined #zig
slowtyper has quit [Quit: WeeChat 2.7.1]
reductum has quit [Quit: WeeChat 2.7.1]
ur5us has joined #zig
_Vi has quit [Ping timeout: 246 seconds]
slowtyper has joined #zig
jjido has joined #zig
marijnfs has joined #zig
ur5us has quit [Ping timeout: 246 seconds]
mokafolio has quit [Ping timeout: 246 seconds]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
traviss has joined #zig
mokafolio has joined #zig
<traviss>
you could do a switch on @typeInfo(@TypeOf(somevar)). for a float it will be: TypeInfo{ .Float = Float{ .bits = 32 } }
<marijnfs>
I have a struct with function pointers that I set, how can I still use the syntactic sure where i can call the function like a method and the first 'self' argument is set?
<traviss>
adamkowalski this works too: std.meta.trait.is(.Float)(@TypeOf(somevar))
TheLemonMan has joined #zig
dddddd has quit [Ping timeout: 250 seconds]
waleee-cl has joined #zig
jjido has joined #zig
tane has joined #zig
jjido has quit [Client Quit]
scientes has joined #zig
marijnfs_ has joined #zig
daex_ has joined #zig
daex has quit [Ping timeout: 240 seconds]
daex_ has quit [Ping timeout: 250 seconds]
marijnfs1 has joined #zig
marijnfs_ has quit [Ping timeout: 264 seconds]
daex has joined #zig
jjido has joined #zig
daex has quit [Ping timeout: 264 seconds]
jjido has quit [Client Quit]
daex has joined #zig
_Vi has joined #zig
zfoo has quit [Read error: Connection reset by peer]
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 250 seconds]
ifreund has joined #zig
marijnfs1 has quit [Ping timeout: 256 seconds]
marijnfs has joined #zig
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
SyrupThinker has quit [Quit: Gateway shutdown]
dddddd has joined #zig
jjido has joined #zig
<marijnfs>
hmm i'm trying to figure out a pattern
<marijnfs>
I'm working on my event queue, and there is a base event type. Then there are specialized types that embed a base type and set appropriate function pointers (kinda like allocators).
<marijnfs>
But I'm not sure how to manage the memory for those guys
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
slowtyper has quit [Quit: WeeChat 2.7.1]
FireFox317 has joined #zig
marijnfs1 has joined #zig
marijnfs has quit [Ping timeout: 264 seconds]
ugi has joined #zig
<ugi>
hello everyone, i have a question about referencing the struct type idenfifier inside the same struct
<ugi>
i need this to create a valid init method for the struct, but the struct is generic, so it can not be defined at top level
<fengb>
marijnfs: if all the types are defined up-front, simplest way is to use a union
<marijnfs1>
fengb: thanks i'll check it out.
<fengb>
Or you can go the allocator route and define an interface with FPs
<marijnfs1>
FPs?
<marijnfs1>
of function pointers
<fengb>
function pointers yeah
<marijnfs1>
yeah i was doing that, but how do you make a nice interface. The init function should take an allocator?
<marijnfs1>
return a pointer to it's type?
<fengb>
Look at how allocators are implemented
<fengb>
Use a child struct, break out with @fieldParentPtr to find the rest of the data
<marijnfs1>
fengb: yeah I was using that pattern. However somewhere you want to create these structs and manage them.
<marijnfs1>
ideally the deinit of the super method releases it but that's not really possible i think
<fengb>
If the total number of implementations is known ahead of time, I'd recommend just using a union. It'll be similar to how C unions or functional languages handle polymorphic dispatching
<marijnfs1>
could a struct free itself? like if it has an allocator do .free(@This())
<fengb>
Generally we use deinit()
<fengb>
And yes it's possible, but I'm not sure if it's a common pattern to do so
<marijnfs1>
fengb: yeah i see deinit used to release resources managed by the struct. But not the struct itself
SyrupThinker has joined #zig
<bsrd>
Is it possible to mutate Strings with Zig?
<fengb>
[]u8 is mutable but []const u8 is not. Literals are generally stored as []const u8
<shakesoda>
yeah you just have to copy into something mutable
<fengb>
You can do something like `var foo = "hello world".*;` That makes a mutable copy
<shakesoda>
i revisited my file copying problem now that it's morning and i'm not half asleep and it was solved in ~5 minutes, heh
<shakesoda>
i'm not entirely sure what i expected to happen with the original approach, but the brain was definitely not working.
<fengb>
Your subconscious thought about it for 8 hours
<bsrd>
Thanks ^^
<fengb>
bsrd: be careful passing it around though. Immutable strings are allocated in the data section so they're always valid, but mutable strings have lifetimes that must be manually managed
SyrupThinker has quit [Quit: ZNC 1.7.5 - https://znc.in]
<fengb>
Literals are allocated in the data section*. Not all immutables are >_>
SyrupThinker has joined #zig
<TheLemonMan>
read-only data is usually stashed in the rodata segment (only on systems using the ELF format)
<shakesoda>
fengb: my subconscious can't think about something for 8 hours any better than the regular one could
<shakesoda>
besides that, I'm almost certain it'd have been thinking about the book I was reading instead.
ugi has quit [Quit: Leaving]
Akuli has joined #zig
<andrewrk>
TheLemonMan, can I send you a patch to try?
<andrewrk>
it should solve undefined symbol when linking: __tls_get_addr #4748
<TheLemonMan>
sure
<TheLemonMan>
you can also try it yourself by running it on top of #4731
<andrewrk>
sure I'll do that as well. it's the glibc-add-ld branch
<TheLemonMan>
you didn't update link.cpp at all?
<andrewrk>
nope. glibc has .abilist files for ld, the update_glibc script just wasn't looking at them
<andrewrk>
I'm running tests locally with this branch, and then also the branch with 4731 merged in, if tests pass then I'll merge into master
<andrewrk>
btw if you didn't hear it's looking like llvm 10 will release on monday
<andrewrk>
my goal is to have all zig ci ready by then (using rc5)
<scientes>
you don't have to build it if you run Debian
<andrewrk>
TheLemonMan, regarding ld.so, I do not think there is a problem, because we already carefully choose the dynamic linker path name based on the target. whether the symbols are exposed in a .so file named ld.so or another doesn't matter, they're provided at runtime
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
forgot-password has joined #zig
<forgot-password>
When compiling to wasm32-freestanding, do I need something other than mark my functions with `export` for them to show up in JavaScript?
<fengb>
export should be enough
_Vi has quit [Ping timeout: 246 seconds]
<forgot-password>
Hm, weird my exports object only contains `memory` and `_start`
<fengb>
Can you inspect the generated wasm file with wasm2wat?
<forgot-password>
Sure, let me find out where I can get that first
<forgot-password>
While I'm waiting for that to finish: When I run `zig build --verbose-<anything>` I don't get any output. Is that right?
<fengb>
zig build uses your build.zig args parser, not the compiler ones
<andrewrk>
ifreund, you can always make your own .h file, #include stuff there, expose some macros, and then @cImport that file
<ifreund>
alright, will give it a try
marijnfs1 has quit [Quit: Lost terminal]
marijnfs has joined #zig
<TheLemonMan>
andrewrk, is #1265 accepted or still in the limbo?
adamkowalski has joined #zig
<TheLemonMan>
and should `foo() catch |_| { ... }` warn that `_` is unused?
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<andrewrk>
I'll resolve that for you right now
ugi has joined #zig
<andrewrk>
TheLemonMan, there ya go
<marijnfs>
why does the std.buffer.size give len() - 1
<marijnfs>
can't i have an empty buffer?
<andrewrk>
marijnfs, because it maintains a sentinel null byte. perhaps you want std.ArrayList(u8) instead of std.Buffer
<marijnfs>
ah yeah and the buffer init needs the sentinel to be there already i guess
<marijnfs>
shouldn't it take a [:0] or something then?
<marijnfs>
ow wait it reserves the space. Then how do I get a buffer without a size
<marijnfs>
i get a integer overflow when calling span because the buffer is empty. I will investigate
adamkowalski has quit [Ping timeout: 256 seconds]
<forgot-password>
When I use a custom panic handler, how do I make sure it doesn't call itself? If I don't add an unreachable to the end, the compiler complains that is not of type `noreturn`, but `void`.
<marijnfs>
the init() in std.Buffer is a bit strange to me
<marijnfs>
it uses mem.copy but targets self.list.items which should be from the arraylist. however this has one more element than input buffer so it will copy too much no?
<marijnfs>
at least that looks to be causing my issue
<marijnfs>
though i'm not sure
<andrewrk>
forgot-password, you'll have to deal with that possibility in your handler. you can look at how the default panic handler does this for inspiration
<andrewrk>
TheLemonMan just landed an improvement to this exact situation an hour ago
<andrewrk>
marijnfs1, string literals already can coerce to `[:0]const u8`. if you want a mutable one you have to decide where to put the memory
<TheLemonMan>
yeah, you have to include start_windows_tls.zig even for DLLs
<TheLemonMan>
and then you'll hit the gen_h problems I told you before
<andrewrk>
ah, I merged prematurely
<TheLemonMan>
well I didn't know what to do about that, generating the header by hand is maybe the only viable alternative
FireFox317 has joined #zig
<FireFox317>
andrewrk, what time will you be streaming?
<andrewrk>
TheLemonMan, want to send me your diff and i'll take it from there? will just disable gen-h by default and update ziglang.org to not claim this feature
<andrewrk>
I'm guessing it's a small patch to start.zig?
<TheLemonMan>
yep, copy the @import from WinMainCRTStartup into _DllMainCRTStartup
<andrewrk>
FireFox317, 18:30 EST which is in 50 minutes from now
<FireFox317>
nice :)
<TheLemonMan>
Windows has a lot of entry points, WinMain DllMain wWinMain wDllMain WinMainCRTStartup DllMainCRTStartup and I'm pretty sure there are even more
ur5us has quit [Quit: Leaving]
marijnfs has joined #zig
<ifreund>
down to my last error, but I can't seem to figure out how to work around translate c here as it's not an error with something I'm directly using https://paste.rs/lpy
<ifreund>
it's from a header that is imported by one of the headers I import
<mq32>
<ifreund> like that `uint64_t modifiers[];` should be `modifiers: [*c]u64,` right?
<mq32>
this should be [*]u64
<mq32>
not c pointer
<mq32>
you know that it's an array, not a pointer-to-one
mmx8705 has joined #zig
jmiven_ has joined #zig
mmx870 has quit [Quit: Ping timeout (120 seconds)]
jmiven has quit [Ping timeout: 246 seconds]
mmx8705 is now known as mmx870
ur5us has quit [Ping timeout: 260 seconds]
_Vi has quit [Ping timeout: 246 seconds]
<ifreund>
true
<ifreund>
yeah I think it does work, I was initially thinking the fact that it's a flexible array made things different, but for the purposes of linking at least it's just a pointer
jzelinskie has quit [Ping timeout: 246 seconds]
dtz has quit [Ping timeout: 246 seconds]
lqd has quit [Ping timeout: 246 seconds]
lqd_ has joined #zig
<fengb>
Oh it’s a struct vararray? Zig doesn’t support that :/
jzelinskie has joined #zig
<fengb>
One way to emulate it is defining it as `modifiers: [1]u64` and accessing with `@ptrCast([*]u64, &foo.modifiers)`
<ifreund>
all I need to do is link to it, I just changed the c header to read `uint64_t *modifiers;` and it compiled/seems to run fine
<fengb>
But that’s probably broken because the data is stored inside the struct, not as a pointer