aboutsummaryrefslogtreecommitdiff
path: root/src/zilch/app/root.wasm.zig
blob: c94c491d141ca501c6aa84ca79fdaff44917a480 (plain)
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
const std = @import("std");

const Options = @import("Options.zig");

pub fn App(comptime options: Options) type {
    var names: [options.globals.len][]const u8 = undefined;
    var types: [options.globals.len]type = undefined;
    var attrs: [options.globals.len]std.builtin.Type.Struct.FieldAttributes = undefined;

    for (options.globals, 0..) |field, index| {
        names[index] = field.name;
        types[index] = field.type;
        attrs[index] = .{};
    }

    const G = @Struct(.auto, null, &names, &types, &attrs);
    return struct {
        globals: G = g: {
            var gl: G = undefined;

            for (options.globals, 1..) |field, id| {
                @field(gl, field.name) = @ptrFromInt(id);
            }

            break :g gl;
        },

        pub const init: @This() = .{};

        comptime {
            for (options.components) |component| {
                component.exportLinks();
            }
        }
    };
}