diff --git a/src/lib/buzz_std.zig b/src/lib/buzz_std.zig index 6b2a2080..946952b1 100644 --- a/src/lib/buzz_std.zig +++ b/src/lib/buzz_std.zig @@ -165,15 +165,18 @@ export fn assert(ctx: *api.NativeCtx) c_int { const message_value = ctx.vm.bz_peek(0); if (!condition_value.boolean()) { - var len: usize = 0; - const message = api.Value.bz_valueToString(message_value, &len).?; - // TODO: debug.getTrace - std.io.getStdOut().writer().print( - "Assert failed: {s}\n", - .{ - message[0..len], - }, - ) catch unreachable; + if (message_value.isObj()) { + var len: usize = 0; + const message = api.Value.bz_valueToString(message_value, &len).?; + std.io.getStdOut().writer().print( + "Assert failed: {s}\n", + .{ + message[0..len], + }, + ) catch unreachable; + } else { + std.io.getStdOut().writer().print("Assert failed\n", .{}) catch unreachable; + } std.os.exit(1); } diff --git a/src/lib/std.buzz b/src/lib/std.buzz index 8f3e3ce3..601a7fcd 100644 --- a/src/lib/std.buzz +++ b/src/lib/std.buzz @@ -1,7 +1,7 @@ || If condition is false print message and exit program || @param condition assert condition || @param message message printed if `condition` is false -export extern fun assert(bool condition, str message) > void; +export extern fun assert(bool condition, str? message = null) > void; || Prints value on stdout || @param value value to print