test wasm of the term package

This commit is contained in:
Mitchell Hashimoto
2022-08-17 13:57:21 -07:00
parent ead6e5a435
commit 2457454b07
6 changed files with 59 additions and 4 deletions

View File

@@ -1,5 +1,8 @@
// This is the C-ABI API for the terminal package. This isn't used
// by other Zig programs but by C or WASM interfacing.
//
// NOTE: This is far, far from complete. We did a very minimal amount to
// prove that compilation works, but we haven't completed coverage yet.
const std = @import("std");
const builtin = @import("builtin");
@@ -7,10 +10,10 @@ const Allocator = std.mem.Allocator;
const Terminal = @import("main.zig").Terminal;
// The allocator that we want to use.
const alloc = if (builtin.target.isWasm())
std.heap.page_allocator
const alloc = if (builtin.link_libc)
std.heap.c_allocator
else
std.heap.c_allocator;
std.heap.page_allocator;
export fn terminal_new(cols: usize, rows: usize) ?*Terminal {
const term = Terminal.init(alloc, cols, rows) catch return null;
@@ -25,3 +28,9 @@ export fn terminal_free(ptr: ?*Terminal) void {
alloc.destroy(v);
}
}
export fn terminal_print(ptr: ?*Terminal, char: u32) void {
if (ptr) |t| {
t.print(@intCast(u21, char)) catch return null;
}
}