diff options
Diffstat (limited to 'src/z/App/root.zig')
| -rw-r--r-- | src/z/App/root.zig | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/z/App/root.zig b/src/z/App/root.zig index d684248..326f3c0 100644 --- a/src/z/App/root.zig +++ b/src/z/App/root.zig @@ -2,19 +2,25 @@ const builtin = @import("builtin"); const std = @import("std"); const h = @import("html"); -pub const Options = struct { name: []const u8 }; +pub const Options = struct { + name: []const u8, + globals: []const Global, -pub fn App(comptime options: Options, globals: anytype) type { - const info = @typeInfo(@TypeOf(globals)).@"struct"; + pub const Global = struct { + name: []const u8, + type: type, + }; +}; +pub fn App(comptime options: Options) type { if (builtin.target.cpu.arch.isWasm()) { - var names: [info.fields.len][]const u8 = undefined; - var types: [info.fields.len]type = undefined; - var attrs: [info.fields.len]std.builtin.Type.StructField.Attributes = undefined; + var names: [options.globals.len][]const u8 = undefined; + var types: [options.globals.len]type = undefined; + var attrs: [options.globals.len]std.builtin.Type.StructField.Attributes = undefined; - for (info.fields, 0..) |field, index| { + for (options.globals, 0..) |field, index| { names[index] = field.name; - types[index] = @field(globals, field.name); + types[index] = field.type; attrs[index] = .{}; } @@ -23,7 +29,7 @@ pub fn App(comptime options: Options, globals: anytype) type { globals: G = g: { var gl: G = undefined; - for (info.fields, 1..) |field, id| { + for (options.globals, 1..) |field, id| { @field(gl, field.name) = @ptrFromInt(id); } @@ -47,7 +53,7 @@ pub fn App(comptime options: Options, globals: anytype) type { .native(.script, .{}, .content(reg: { var register_code: []const u8 = ""; - for (info.fields, 1..) |field, id| { + for (options.globals, 1..) |field, id| { register_code = register_code ++ std.fmt.comptimePrint( "ObjectStore.registerObject({}, {s});", .{ id, field.name }, |