-
Notifications
You must be signed in to change notification settings - Fork 36
/
intermediate.zig
48 lines (40 loc) · 1.47 KB
/
intermediate.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
45
46
47
48
const std = @import("std");
const fs = std.fs;
const mapping = @import("type_mapping.zig");
const json = std.json;
pub const jsonFiles: []const []const u8 = &.{
"raylib.json",
"rlgl.json",
"raymath.json",
};
pub const bindingsJSON = "bindings.json";
pub fn main() !void {
std.log.info("updating bindings.json ...", .{});
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
if (gpa.deinit() == .leak) {
std.log.err("memory leak detected", .{});
}
}
const allocator = gpa.allocator();
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
const raylib: mapping.CombinedRaylib = try mapping.CombinedRaylib.load(arena.allocator(), jsonFiles);
var bindings: mapping.Intermediate = mapping.Intermediate.loadCustoms(arena.allocator(), bindingsJSON) catch |err| Catch: {
std.log.warn("could not open {s}: {?}\n", .{ bindingsJSON, err });
break :Catch mapping.Intermediate{
.enums = &[_]mapping.Enum{},
.structs = &[_]mapping.Struct{},
.functions = &[_]mapping.Function{},
.defines = &[_]mapping.Define{},
};
};
try bindings.addNonCustom(arena.allocator(), raylib);
var file = try fs.cwd().createFile(bindingsJSON, .{});
defer file.close();
try json.stringify(bindings, .{
.emit_null_optional_fields = false,
.whitespace = .indent_2,
}, file.writer());
std.log.info("... done", .{});
}