Skip to main content

luaur_common/functions/
assert_call_handler.rs

1use crate::functions::assert_handler::assert_handler;
2use crate::macros::luau_noinline::LUAU_NOINLINE;
3use core::ffi::c_char;
4
5LUAU_NOINLINE! {
6    pub fn assert_call_handler(
7        expression: *const c_char,
8        file: *const c_char,
9        line: i32,
10        function: *const c_char,
11    ) -> i32 {
12        let handler_ptr = assert_handler();
13        if let Some(handler) = *handler_ptr {
14            unsafe {
15                return handler(expression, file, line, function);
16            }
17        }
18
19        // No custom handler: print the assertion before LUAU_DEBUGBREAK traps the
20        // process (matches the C++ default `assertCallHandler`, which writes the
21        // message to stderr). Without this the failure is a silent `int 3`, which on
22        // Windows surfaces only as a 0xC0000003 abort with no indication of which
23        // assert fired — making platform-specific assertion failures undiagnosable.
24        #[cfg(feature = "std")]
25        unsafe {
26            let expr = core::ffi::CStr::from_ptr(expression).to_string_lossy();
27            let f = core::ffi::CStr::from_ptr(file).to_string_lossy();
28            eprintln!("LUAU_ASSERT failed: {} ({}:{})", expr, f, line);
29        }
30
31        1
32    }
33}