aboutsummaryrefslogtreecommitdiff
path: root/src/z/App
diff options
context:
space:
mode:
Diffstat (limited to 'src/z/App')
-rw-r--r--src/z/App/main.js9
-rw-r--r--src/z/App/root.zig26
2 files changed, 16 insertions, 19 deletions
diff --git a/src/z/App/main.js b/src/z/App/main.js
index 6251a47..a875c1d 100644
--- a/src/z/App/main.js
+++ b/src/z/App/main.js
@@ -20,18 +20,9 @@ const imports = {
WebAssembly.instantiateStreaming(fetch("index.wasm"), imports).then(
({ instance, module }) => {
- const is64 = new Uint8Array(
- instance.exports.memory.buffer,
- instance.exports.bit_length,
- 1,
- )[0] == 8
-
window.wasm = {
exports: instance.exports,
memory: instance.exports.memory,
- is64: is64,
- UsizeArray: is64 ? BigUint64Array : Uint32Array,
- IsizeArray: is64 ? BigInt64Array : Int32Array,
}
wasm.exports.run();
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 },