@@ -48,6 +48,7 @@ pub const Compiler = @import("compile.zig").Compiler;
4848const userdata = @import ("userdata.zig" );
4949const stack = @import ("stack.zig" );
5050const alloc = @import ("alloc.zig" ).alloc ;
51+ const assert = @import ("assert.zig" );
5152
5253/// High-level Lua wrapper and main library entry point.
5354/// Provides an idiomatic Zig interface with automatic type conversions for the Luau scripting language.
@@ -65,6 +66,9 @@ pub const Lua = struct {
6566 Compile ,
6667 };
6768
69+ /// Assert handler function type for Luau VM assertions.
70+ pub const AssertHandler = assert .AssertHandler ;
71+
6872 /// Initialize a new Lua state with optional custom allocator.
6973 ///
7074 /// Creates a new Luau virtual machine instance. Pass `null` to use Luau's built-in
@@ -939,6 +943,27 @@ pub const Lua = struct {
939943
940944 return list .toOwnedSlice ();
941945 }
946+
947+ /// Set a custom assert handler for Luau VM assertions.
948+ ///
949+ /// The assert handler is called when a Luau VM assertion fails, allowing custom error
950+ /// handling and debugging. The handler receives information about the failed assertion
951+ /// including expression, file, line number, and function name.
952+ ///
953+ /// Example:
954+ /// ```zig
955+ /// fn myAssertHandler(expr: [*c]const u8, file: [*c]const u8, line: c_int, func: [*c]const u8) callconv(.C) c_int {
956+ /// std.debug.print("Assertion failed: {s} at {s}:{} in {s}\n", .{expr, file, line, func});
957+ /// return 0; // Return 0 to abort
958+ /// }
959+ ///
960+ /// Lua.setAssertHandler(myAssertHandler);
961+ /// ```
962+ ///
963+ /// Note: The handler function must have C calling convention and return 0 to abort or non-zero to continue.
964+ pub inline fn setAssertHandler (handler : AssertHandler ) void {
965+ assert .setAssertHandler (handler );
966+ }
942967};
943968
944969const expect = std .testing .expect ;
0 commit comments