diff --git a/samples/calc-zig/.gitignore b/samples/calc-zig/.gitignore index 53d00b4..8de307e 100644 --- a/samples/calc-zig/.gitignore +++ b/samples/calc-zig/.gitignore @@ -1,5 +1,6 @@ Calc zig-out zig-cache +liborca.a profile.dtrace profile.spall diff --git a/samples/calc-zig/build.bat b/samples/calc-zig/build.bat index 3c1c2ff..b70641c 100644 --- a/samples/calc-zig/build.bat +++ b/samples/calc-zig/build.bat @@ -6,6 +6,7 @@ set wasmFlags=--target=wasm32^ -fno-builtin ^ -Wl,--no-entry ^ -Wl,--export-dynamic ^ + -Wl,--relocatable ^ -g ^ -O2 ^ -mbulk-memory ^ diff --git a/samples/calc-zig/src/main.zig b/samples/calc-zig/src/main.zig index 8920804..a1e852c 100644 --- a/samples/calc-zig/src/main.zig +++ b/samples/calc-zig/src/main.zig @@ -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()); } diff --git a/src/orca.zig b/src/orca.zig index 322478b..1e71133 100644 --- a/src/orca.zig +++ b/src/orca.zig @@ -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;