zig proof of concept is working

This commit is contained in:
Reuben Dunnington 2023-09-11 20:50:05 -07:00
parent 02c1938a43
commit bded79d363
Signed by: rdunnington
GPG Key ID: 3D57C8938EA08E90
4 changed files with 22 additions and 11 deletions

View File

@ -1,5 +1,6 @@
Calc
zig-out
zig-cache
liborca.a
profile.dtrace
profile.spall

View File

@ -6,6 +6,7 @@ set wasmFlags=--target=wasm32^
-fno-builtin ^
-Wl,--no-entry ^
-Wl,--export-dynamic ^
-Wl,--relocatable ^
-g ^
-O2 ^
-mbulk-memory ^

View File

@ -1,10 +1,21 @@
const std = @import("std");
const oc = @import("orca");
var counter: u32 = 0;
export fn oc_on_init() void {
oc.log_info("oc_on_init!!!!\n");
oc.log_info("counter: {}", .{counter}, @src());
}
export fn oc_on_frame_refresh() void {
oc.log_info("oc_on_frame_refresh!!!!\n");
counter += 1;
oc.log_info("counter: {}", .{counter}, @src());
if (counter == 10) {
oc.oc_request_quit();
}
}
export fn oc_on_terminate() void {
oc.log_info("byebye", .{}, @src());
}

View File

@ -1,17 +1,15 @@
const std = @import("std");
const c = @cImport({
@cDefine("__ORCA__", "");
@cInclude("orca.h");
});
// export var oc_rawEvent: c.oc_event = c.oc_rawEvent;
pub fn log_info(comptime fmt: []const u8, args: anytype, source: std.builtin.SourceLocation) void {
var format_buf: [512:0]u8 = undefined;
_ = std.fmt.bufPrintZ(&format_buf, fmt, args) catch 0; // just discard NoSpaceLeft error for now
pub fn log_info(fmt: []const u8) void {
c.oc_log_ext(c.OC_LOG_LEVEL_INFO, "UnknownFunc", "UnknownFile", 0, fmt.ptr);
var line: c_int = @intCast(source.line);
c.oc_log_ext(c.OC_LOG_LEVEL_INFO, source.fn_name.ptr, source.file.ptr, line, format_buf[0..].ptr);
}
// ORCA_API void oc_log_ext(oc_log_level level,
// const char* function,
// const char* file,
// int line,
// const char* fmt,
// ...);
pub const oc_request_quit = c.oc_request_quit;