ziglua icon indicating copy to clipboard operation
ziglua copied to clipboard

Define apicheck function to use a Zig panic

Open natecraddock opened this issue 1 year ago • 2 comments

From a quick glance at the Lua sources, it may be possible to override the use of assert.h for the API check with a custom function. If so, this would make api checks much more easy to debug with zig panics and stack traces.

natecraddock avatar Mar 20 '24 00:03 natecraddock

this is doable from consumer code:

pub fn main() void {
    // ...
    var act: std.posix.Sigaction = .{
        .handler = .{ .handler = handleAbrt },
        .mask = switch (builtin.os.tag) {
            .macos => 0,
            .linux => std.posix.empty_sigset,
            else => @compileError("os not supported"),
        },
        .flags = 0,
    };
    std.posix.sigaction(std.posix.SIG.ABRT, &act, null) catch {}; // if it doesn't work, we just crash the old way lol
    // ...
}

fn handleAbrt(_: c_int) callconv(.C) noreturn {
    @call(.always_inline, std.debug.panic, .{ "assertion failed!!", .{} });
}

robbielyman avatar Jun 05 '24 17:06 robbielyman