-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.zig
44 lines (43 loc) · 1.43 KB
/
example.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const std = @import("std");
const ini = @import("ini.zig");
const file = @embedFile("test.ini");
pub fn main() !void {
var pos: usize = 0;
var state = ini.State.normal;
while (ini.getTok(file, &pos, &state)) |tok| {
switch(tok) {
.section => |section| std.debug.print("section `{s}`\n", .{section}),
.key => |key| std.debug.print("key `{s}`\n", .{key}),
.value => |value| std.debug.print("value `{s}`\n", .{value}),
.comment => std.debug.print("comment\n", .{}),
}
}
const TestingConfig = struct {
core: struct {
foo: []const u8,
goo: isize,
cool: bool
}
};
const lol = TestingConfig {
.core = .{
.foo = "bar",
.goo = 32,
.cool = true
}
};
try ini.writeStruct(lol, std.io.getStdErr().writer());
const NewConfig = struct {
core: struct {
repositoryformatversion: isize,
filemode: bool,
bare: bool,
logallrefupdates: bool
}
};
const str = try ini.readToStruct(NewConfig, file);
std.debug.print("core.repositoryformatversion: {}\n", .{str.core.repositoryformatversion});
std.debug.print("core.filemode: {}\n", .{str.core.filemode});
std.debug.print("core.bare: {}\n", .{str.core.bare});
std.debug.print("core.logallrefupdates: {}\n", .{str.core.logallrefupdates});
}