ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
quc has quit [Ping timeout: 252 seconds]
<donpdonp> andrewrk: thx for the comments and for tolerating my low-sleep-inspired frustration
<donpdonp> i noticed json.zig in master branch so now im using master for this project :)
<donpdonp> got a casting err that isnt entirely clear, looks up "Casting" docs section: TODO: explain implicit vs explicit casting. hehe
<donpdonp> i dont mind the bleeding edge.
<darithorn> what's the error?
<donpdonp> error: integer value 0 cannot be implicitly casted to type 'CURLcode'
<donpdonp> if(res == c.CURLE_OK) {
<donpdonp> ^
<donpdonp> c.CURLcode(c.CURLE_OK) is working.
<donpdonp> which is kind of funny in that its the opposite of a C cast (int)45L where the parens go around the type
<donpdonp> zig 0.2.0 was happy with the bare c.CURLE_OK
<darithorn> yeah it's a bit easier to parse since it looks like a function call
<donpdonp> of course now that var res is of type c.CUREcode, I cant warn "{}", res cause it doesnt know what to do with that type
<darithorn> you could always cast it back to an i32 or whatever type fits best
<donpdonp> error: enum to integer cast to 'i32' instead of its tag type, 'c_int'
<donpdonp> warn("curl ERR {} {}\n", i32(res), std.cstr.toSliceConst(err_cstr));
<donpdonp> ok so c_int, I think to myself
<donpdonp> oh i was going to show an error, but I forgot to put a c_int() in a second location.
<donpdonp> well it looks happy now :)
<donpdonp> pub fn openWriteNoClobber(allocator: &mem.Allocator, path: []const u8, file_mode: os.FileMode)
<donpdonp> what is file_mode in that case? usually the mode implies read/write/overwrite but the function name is already specifying that
<donpdonp> oh its the unix file perms. std.os.default_file_mode
<donpdonp> if (std.os.File.openWriteNoClobber(allocator, filename, std.os.default_file_mode)) |file| {
<donpdonp> file.write("");
<donpdonp> here's a new one -> error: expected type '&File', found '&const File'
<darithorn> try |*file|
<donpdonp> that did it. thx
<donpdonp> var json_parser = std.json.JsonParser.init(allocator, true);
<donpdonp> error: 'JsonParser' is private
<donpdonp> any ideas how to use the new json.zig?
<andrewrk> donpdonp, try looking at the tests in that file
<darithorn> i recently was messing with the json api in the std lib and everything is private
<darithorn> i modified the json.zig file where it's stored in my system to make JsonParser public
<donpdonp> andrewrk: the test's first line is var p = JsonParser.init(std.debug.global_allocator, false);
<donpdonp> which seems like what im gdoing
<darithorn> also there's a bug (or maybe just a different standard?) where the root node is an array that contains objects in it
<darithorn> you get 'error: InvalidValueBegin'
<donpdonp> o^O
<darithorn> it needs at least two objects in the array to fail "[{},{}]"
<donpdonp> ok. my .json files are all {} root
<donpdonp> is there a convenient way to print a ValueTree
<donpdonp> warn("json value {}\n", value_tree.root.dump()); => error: compiler bug: var args can't handle void. https://github.com/zig-lang/zig/issues/557
<darithorn> dump already prints it for you
<darithorn> value_tree.root.dump()
<donpdonp> interesting....
<donpdonp> value_tree.root.Object is a HashMap([]const u8,Value...
<donpdonp> how do I access a key? Object['key'] isnt it
<darithorn> if (obj.get("key")) |value| {}
<donpdonp> thx
<donpdonp> how do i instance some u8 data
<donpdonp> var json_str: []u8 = (....) (lets say 2048 bytes)
<darithorn> you can initialize it to zero by doing []u8{0} ** 2048
<darithorn> that would make it 2048 elements large
<donpdonp> error: expected type '[]u8', found '[1]u8'
<donpdonp> var json_str: []u8 = []u8{0};
<donpdonp> (similar error with ** 2048)
<darithorn> oh, yeah, you need to make the type of json_str be [2048]u8
<donpdonp> hmm ok. i thought the point of []u8 was it could point to an array of any length
<donpdonp> var json_str: [2048]u8 = []u8{0} ** 2048;
<donpdonp> file.read(json_str);
<donpdonp> file.read: error: expected type '[]u8', found '[2048]u8'
<donpdonp> i would really have thought []u8{1} would be a type []u8 of length 1 instead of [1]u8. hmmm
<darithorn> you should be able to turn it into a slice so you can work with read
<darithorn> file.read(json_str[0..]);
<donpdonp> file.read(json_str[0..]); => error: expression value is ignored
* donpdonp grrrrs
<darithorn> read returns what was read, you can't ignore it implicitly
<darithorn> either set it to a variable or do _ = file.read(json_str[0..]);
<donpdonp> oh thta value. i thought it was talking about the parameter value
* donpdonp nods
<donpdonp> 'expression return value is ignored' is a bug i should file :)
<darithorn> yeah, the errors need to be reworked so they're more clear
<donpdonp> warn("some json {}\n", json_str); => some json {
<donpdonp> "url": "https://donp.org"
<donpdonp> }
<donpdonp> try json_parser.parse(json_str); => error.InvalidTopLevelTrailing
<donpdonp> looks valid to meeeeee....
<darithorn> i think it may be because of the trailing zeros in that json_str buffer you create
<darithorn> an easy way that I know of to dynamically read the entire contents of a file is to use std.io.readFileAlloc
<donpdonp> hmmm
<donpdonp> so close
<donpdonp> var json_file = std.io.readFileAlloc(allocator, filename);
<donpdonp> var value_tree = try json_parser.parse(json_file);
<donpdonp> error: expected type '[]const u8', found '@typeOf(readFileAlloc).ReturnType.ErrorSet![]u8'
<donpdonp> var value_tree = try json_parser.parse(json_file);
<donpdonp> ah the readFilealloc has to be 'unwound'
tiehuis has joined #zig
<darithorn> yeah you need to put `try` in front of it
<donpdonp> whoho! got past the parsing part.
<donpdonp> if (root.Object.get("url")) |url| {
<donpdonp> warn("settings url {}\n", url.value);
<donpdonp> settings url Value@28c7c8
<donpdonp> why am I getting a value obkect instead of... the value? (a url string)
<tiehuis> the value is a dynamic json type, you need url.value.String
<tiehuis> i think we can make the lookup structure a bit nicer in the future but for now it requires a bit more work
<donpdonp> ok it looks like file.json is making it all the way into a zig data structure. whoho.
<donpdonp> is there a variable for the zig version?
<tiehuis> no
<donpdonp> just when something seems straight forward... warn("{}", builtin.os); -> error: Unable to format type 'Os'
<tiehuis> do @tagName(builtin.os)
<donpdonp> thx
<GitHub96> [zig] tiehuis pushed 1 new commit to master: https://git.io/vhvZ2
<GitHub96> zig/master 698c52e Marc Tiehuis: Make StreamingJsonParser public
<donpdonp> also JsonParser ^
<GitHub37> [zig] tiehuis pushed 1 new commit to master: https://git.io/vhvZr
<GitHub37> zig/master 4f4afe1 Marc Tiehuis: Make JsonParser public
<donpdonp> tiehuis++
darithorn has quit [Quit: Leaving]
<tiehuis> quick test of json performance since i never tested before:
<tiehuis> the streaming parser is about 200Mb/s throughput for me on an i5-6500
<tiehuis> https://github.com/kostya/benchmarks, it'd be ~1.0-1.2s here.
darithorn has joined #zig
<donpdonp> ug. confused again with uniontypes
<donpdonp> var value_tree: std.json.ValueTree = json_parser.parse("{}"); => error: expected type 'ValueTree', found '@typeOf(JsonParser_parse).ReturnType.ErrorSet!ValueTree'
<donpdonp> that makes sense, its a uniontype return
<donpdonp> so I add 'try parse' which should return the ValueTree to the variable, or return the error for the enclosing function
<donpdonp> var value_tree: std.json.ValueTree = try json_parser.parse("{}"); => error: expected type 'void', found '@typeOf(JsonParser_parse).ReturnType.ErrorSet'
<donpdonp> instead I get expected type void.
<donpdonp> ohh the enclosing function's return type was void and not !void. fixed.
<andrewrk> donpdonp, there are some improvements to compile errors to be made
* donpdonp nods
<donpdonp> warn("client json {}\n", @typeOf(json)); => error: parameter of type 'type' requires comptime
<andrewrk> donpdonp, use @typeName: https://ziglang.org/documentation/master/#typeName
<donpdonp> /home/donp/code/zig/zigdeck/src/main.zig:16:55: error: expected type 'type', found 'Value'
<donpdonp> warn("client activitypub ID {} {}\n", @typeName(json), (??json.Object.get("id")).value.String);
<andrewrk> @typeName(@typeOf(json))
<donpdonp> o^O
<andrewrk> you can also use @compileLog to look at comptime values
<andrewrk> @compileLog(@typeOf(json))
<donpdonp> nod.
<donpdonp> well i learned some things today.
<donpdonp> does zig interface with .cpp as well as C?
<andrewrk> no
<andrewrk> I'm headed to bed. I'll be around tomorrow. good night!
<donpdonp> may the zig be with you.
tiehuis has quit [Ping timeout: 260 seconds]
MajorLag2 has quit [Read error: Connection reset by peer]
MajorLag1 has joined #zig
quc has joined #zig
return0e has quit [Ping timeout: 264 seconds]
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
return0e has joined #zig
return0e has quit [Ping timeout: 252 seconds]
davr0s has joined #zig
return0e has joined #zig
darithorn_ has joined #zig
darithorn has quit [Ping timeout: 245 seconds]
jjido has joined #zig
occivink has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<andrewrk> donpdonp, I'm available now if you ran into any more issues
Ichorio has joined #zig
davr0s has joined #zig
jjido has quit [Ping timeout: 240 seconds]
bheads_ has joined #zig
bheads has quit [Ping timeout: 240 seconds]
jjido has joined #zig
return0e has quit [Ping timeout: 252 seconds]
return0e_ has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
SimonNa has joined #zig
quc has quit [Remote host closed the connection]
jjido has quit [Ping timeout: 252 seconds]
Ichorio has quit [Ping timeout: 245 seconds]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
darithorn_ has quit [Read error: Connection reset by peer]
darithorn has joined #zig