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