aboutsummaryrefslogtreecommitdiff
path: root/src/z/App/root.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-06 15:08:13 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-06 15:08:13 +0200
commit12a02f161504b49a54243bed996df6b44e25b7b4 (patch)
tree5aa9d142a6faba51730d0eeb69ffc0a0766d21c6 /src/z/App/root.zig
parenta4b2398aba2211ce5901ceb46f73057864bd1707 (diff)
refactor wasm
Diffstat (limited to 'src/z/App/root.zig')
-rw-r--r--src/z/App/root.zig26
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 },