Skip to content

Add register main macro as alternative to agb::entry proc macro #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions agb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@ fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
loop {}
}

#[macro_export]
macro_rules! register_main {
($entry_point: ident) => {
const fn entry_point_function_is_invalid(_: fn($crate::Gba) -> !) {}

const _: () = entry_point_function_is_invalid($entry_point);

#[cfg(not(test))]
#[export_name = "main"]
pub extern "C" fn entry_point() -> ! {
let gba = unsafe { $crate::Gba::new_in_entry() };
$entry_point(gba);
}

#[cfg(test)]
#[export_name = "main"]
pub extern "C" fn entry_point() -> ! {
let gba = unsafe { $crate::Gba::new_in_entry() };
$crate::test_runner::agb_start_tests(gba, test_main);
}
};
}

/// The Gba struct is used to control access to the Game Boy Advance's hardware in a way which makes it the
/// borrow checker's responsibility to ensure no clashes of global resources.
///
Expand Down