Skip to main content

luaur_code_gen/macros/
codegen_assert.rs

1//! Node: `cxx:Macro:Luau.CodeGen:CodeGen/include/Luau/CodeGenCommon.h:CODEGEN_ASSERT`
2//! (hand-fixed: the original translation passed `&str` where the handler
3//! takes `*const c_char` and could never have expanded; mirrors LUAU_ASSERT!)
4
5#[macro_export]
6macro_rules! CODEGEN_ASSERT {
7    ($expr:expr) => {
8        if !($expr) {
9            if luaur_common::assert_call_handler(
10                concat!(stringify!($expr), "\0").as_ptr() as *const core::ffi::c_char,
11                concat!(file!(), "\0").as_ptr() as *const core::ffi::c_char,
12                line!() as i32,
13                c"unknown".as_ptr(),
14            ) != 0
15            {
16                luaur_common::LUAU_DEBUGBREAK!();
17            }
18        }
19    };
20    // Tolerant 2-arg form: the C++ `CODEGEN_ASSERT(cond && "message")` idiom
21    // routinely lands as `CODEGEN_ASSERT!(cond, "message")`. Accept it (mirrors
22    // the LUAU_ASSERT! tolerance) instead of failing on the separator.
23    ($expr:expr, $msg:expr) => {
24        if !($expr) {
25            if luaur_common::assert_call_handler(
26                concat!(stringify!($expr), " : ", stringify!($msg), "\0").as_ptr()
27                    as *const core::ffi::c_char,
28                concat!(file!(), "\0").as_ptr() as *const core::ffi::c_char,
29                line!() as i32,
30                c"unknown".as_ptr(),
31            ) != 0
32            {
33                luaur_common::LUAU_DEBUGBREAK!();
34            }
35        }
36    };
37}
38
39pub use CODEGEN_ASSERT;