luaur_common/macros/luau_assert.rs
1#[allow(non_snake_case)]
2#[macro_export]
3macro_rules! LUAU_ASSERT {
4 ($expr:expr) => {
5 if $crate::macros::luau_assertenabled::LUAU_ASSERTENABLED {
6 if !($expr) {
7 // `assertCallHandler` takes C strings; `stringify!`/`file!`
8 // produce string literals, so nul-terminate them to hand over a
9 // valid `*const c_char`. (`__FUNCTION__` has no stable Rust
10 // equivalent, so the function name is a placeholder.)
11 $crate::functions::assert_call_handler::assert_call_handler(
12 concat!(stringify!($expr), "\0").as_ptr() as *const core::ffi::c_char,
13 concat!(file!(), "\0").as_ptr() as *const core::ffi::c_char,
14 line!() as i32,
15 c"unknown".as_ptr(),
16 );
17 $crate::LUAU_DEBUGBREAK!();
18 }
19 }
20 };
21 // Tolerant 2-arg form: the C++ `LUAU_ASSERT(cond && "message")` idiom (and
22 // `LUAU_ASSERT(!"message")`) routinely lands from the model as a two-token
23 // call `LUAU_ASSERT!(cond, "message")`. Accept it — assert the condition and
24 // carry the message into the assertion text — rather than fail compilation
25 // over a separator. Mirrors the trailing-comma / camelCase tolerances the
26 // foundation already grants machine translations.
27 ($expr:expr, $msg:expr) => {
28 if $crate::macros::luau_assertenabled::LUAU_ASSERTENABLED {
29 if !($expr) {
30 $crate::functions::assert_call_handler::assert_call_handler(
31 concat!(stringify!($expr), " : ", stringify!($msg), "\0").as_ptr()
32 as *const core::ffi::c_char,
33 concat!(file!(), "\0").as_ptr() as *const core::ffi::c_char,
34 line!() as i32,
35 c"unknown".as_ptr(),
36 );
37 $crate::LUAU_DEBUGBREAK!();
38 }
39 }
40 };
41}
42
43pub use LUAU_ASSERT;