ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
atk has quit [Quit: Well this is unexpected.]
atk has joined #zig
<andrewrk>
bb010g, I've never tried building stage 3
<andrewrk>
stage 2 isn't complete so we can't build stage 3 yet
<andrewrk>
the most stage 2 does is `zig fmt`
<darithorn>
is there a way to make sure that a function i've written is done at compile time?
<andrewrk>
darithorn, at the callsite, you can use `comptime`
<darithorn>
ah okay i just wasn't sure how strict it was yet. a lot is available at compile time then! :D
<bb010g>
andrewrk: Ok. It probably wouldn't hurt to note that in the readme. :)
<andrewrk>
bb010g, good idea
<darithorn>
is there a reason you can't assign a variable of type 'type' even though it's comptime? i try to assign it after initialization and i get "attempt to dereference non pointer type 'type'"
<donpdonp>
im trying to take the first step with using a C library from zig.
<donpdonp>
I believe the code is fine, I can run it with $ zig build-exe src/main.zig --library c and everything is happy. what I cant figure out is what to put in build.zig so that $ zig build will produce the same output
<andrewrk>
hi donpdonp. yeah apologies for the lack of documentation
<donpdonp>
given const ui = @cImport({ @cInclude("ui.h"); });, how would I define a zig variable of type uiInitOption?
<andrewrk>
var x: ui.uiInitOption = undefined;
<andrewrk>
I would recommend doing all your C imports in 1 @cImport block and naming the namespace `c`
<donpdonp>
andrewrk: that var declaration worked. wow. thx. zig++
darithorn has quit [Remote host closed the connection]
davr0s has joined #zig
<donpdonp>
warn("ui init sizeof is {}\n", @sizeOf(ui.uiInitOptions)); => main.zig:26:34: error: compiler bug: integer and float literals in var args function must be casted.
<donpdonp>
o^O
<andrewrk>
donpdonp, you can work around like this: usize(@sizeOf(ui.uiInitOptions))
<andrewrk>
you can also print that valueu at compile time:
<andrewrk>
I need to add ReleaseSmall to these docs
<donpdonp>
const mode = b.smallReleaseOptions(); => no member named 'smallReleaseOptions' in struct 'Builder'
<donpdonp>
is that a post 0.20 feature?
<donpdonp>
0.2.0
<donpdonp>
if so, whats the flag to allow compileLog in 0.2.0 without it being an aerror
<donpdonp>
here's another one that comes from the docs but doesnt compile. trying to set the bytes of the struct to 0 with: for (o[0..o_size]) |*b| b.* = 0; -> error: expected token 'Symbol', found '*'
<donpdonp>
for (o[0..o_size]) |*b| b.* = 0;
<donpdonp>
^
<donpdonp>
sorry for the barrage of questions :)
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<andrewrk>
however I suggest tracking master branch
<andrewrk>
I'm going to sleep. have a good night, I will check for questions tomorrow
davr0s has joined #zig
<donpdonp>
goo dnight
alexnask has joined #zig
<donpdonp>
what format characters does zig like?
<donpdonp>
both {h} and {%h} fail (for hex chars). cant find docs on it
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Ichorio has joined #zig
davr0s has joined #zig
quc has joined #zig
Hejsil has joined #zig
<Hejsil>
donpdonp, {x} for hex :)
* donpdonp
slaps forehead
<donpdonp>
warn("hex {x}", 0x123a); error: compiler bug: integer and float literals in var args
<donpdonp>
should i be using zig master-branch?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<donpdonp>
warn("hex {x}", usize(0x123a)); works as expected though im not sure what usize() is doing
<Hejsil>
Zig has the concept of a compile time int (and float). These are bigints, and cannot exists in the final binary. They cast to all integer types that they fit into
<Hejsil>
For now, you can't pass comptime ints to varargs functions
<Hejsil>
usize() is a cast
<donpdonp>
Hejsil: can i use "{}" for a function that return a c-string
<donpdonp>
or rather, how would I? I get "u8@7fab84312fc8"
<Hejsil>
You could do std.debug.warn("{}", std.cstr.toSliceConst(c"Hello World!\n"))
<Hejsil>
I don't think there is any way to specify in the format string that your '&const u8' is a c strings
<Hejsil>
Do you know that you're string have a null terminating byte?
<Hejsil>
If soo, then you can just do slice.ptr
<Hejsil>
If not, then do const s = addNullByte(allocator, slice); useS(s.ptr);
<donpdonp>
well im using curl(c"http://") works fine. func(url: []const u8) { curl(url) } dies
<donpdonp>
where func("http://") is called (not a c"")
<Hejsil>
c"" gives you &u8, while "" gives []u8
<Hejsil>
Aka, "" gives you a slice which is a ptr and a length
<Hejsil>
"" won
<Hejsil>
"" wont have a null terminated byte
<Hejsil>
Because you're suppose to use s.len to figure out the end
<Hejsil>
c"" will have a null terminated byte, so you just get a pointer to the start of the string
<donpdonp>
where does 'allocator' come from
<Hejsil>
If you want to append an extra charactor to your string (the null terminator in this case) you have to allocate (on the heap or somewhere else)
<Hejsil>
In Zig, the way you allocate memory is by passing around allocators
<donpdonp>
okay so how i get an allocator
<Hejsil>
For debugging, you can use std.debug.global_allocator
<donpdonp>
var allocator = std.debug.global_allocator;
<donpdonp>
var cstr = std.cstr.addNullByte(allocator, url);
<donpdonp>
curl(url) still fails :( (where c"url-here" works)
<donpdonp>
curl(cstr) I mean
<Hejsil>
cstr.ptr and it should work
<donpdonp>
c.curl_easy_setopt(curl, c.CURLOPT_URL, cstr.ptr); => error: type '@typeOf(addNullByte).ReturnType.ErrorSet![]u8' does not support field access
<Hejsil>
Aaah
<Hejsil>
Right
<Hejsil>
addNullByte can fail
<Hejsil>
So you have to catch the error
<Hejsil>
Either by passing it up
<Hejsil>
try cstr.addNullByte(allocator, slice)
<Hejsil>
Or by handeling it
<donpdonp>
ug. allocating a single byte shouldnt require exception handling :)
<Hejsil>
cstr.addNullByte(allocator, slice) catch |err| { handle error here };
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
<donpdonp>
omg this is the hardest part of this whole project
<donpdonp>
going from a zigstr to a cstr.
<donpdonp>
anyone have an example code?
<donpdonp>
var cstr: []u8 = std.cstr.addNullByte(&allocator.allocator, url); -> error: expected type '[]u8', found '@typeOf(addNullByte).ReturnType.ErrorSet![]u8'