diff options
Diffstat (limited to 'src/zilch/bridge')
| -rw-r--r-- | src/zilch/bridge/root.zig | 40 | ||||
| -rw-r--r-- | src/zilch/bridge/server.root.zig | 10 | ||||
| -rw-r--r-- | src/zilch/bridge/wasm.root.zig | 0 |
3 files changed, 50 insertions, 0 deletions
diff --git a/src/zilch/bridge/root.zig b/src/zilch/bridge/root.zig new file mode 100644 index 0000000..166aadc --- /dev/null +++ b/src/zilch/bridge/root.zig @@ -0,0 +1,40 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +const mod = @import("../root.zig"); +const Env = mod.Env; +const Function = Env.Function; + +const wasm = @import("wasm.root.zig"); +const server = @import("server.root.zig"); + +pub fn Bridge(T: type) type { + if (builtin.target.cpu.arch.isWasm()) { + return wasm.Bridge(T); + } else { + return server.Bridge(T); + } +} + +pub const Context = struct { + gpa: std.mem.Allocator, + arena: std.mem.Allocator, + io: std.Io, +}; + +pub const bindings = struct { + pub const call: Function = .from( + \\async function(ptr, len, result_ptr, len_check) { + \\ const response = await fetch("/api", { + \\ method: "POST", + \\ body: new DateView(wasm.memory.buffer, ptr, len), + \\ }) + \\ const bytes = await response.bytes(); + \\ if (bytes.length != len_check) { + \\ throw "response has incorrect size"; + \\ } + \\ const memory = new Uint8Array(wasm.memory.buffer); + \\ memory.set(bytes, result_ptr); + \\} + ); +}; diff --git a/src/zilch/bridge/server.root.zig b/src/zilch/bridge/server.root.zig new file mode 100644 index 0000000..504286c --- /dev/null +++ b/src/zilch/bridge/server.root.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const http = @import("http"); + +pub fn Bridge(T: type) type { + _ = T; + return struct { + pub fn handle() void { + } + }; +} diff --git a/src/zilch/bridge/wasm.root.zig b/src/zilch/bridge/wasm.root.zig new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/zilch/bridge/wasm.root.zig |