2023-06-09 20:45:06 +00:00
|
|
|
/**
|
|
|
|
* @file Main.cpp
|
|
|
|
* @author apio (cloudapio.eu)
|
|
|
|
* @brief Alternative C++ main function.
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2023, the Luna authors.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-04-13 15:04:59 +00:00
|
|
|
#include <errno.h>
|
2023-05-02 08:50:39 +00:00
|
|
|
#include <os/Main.h>
|
2023-04-13 15:04:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int g_argc;
|
|
|
|
char** g_argv;
|
|
|
|
|
2023-06-09 20:45:06 +00:00
|
|
|
// This function will only be linked into the final binary if the user does not already define main(), which implies
|
|
|
|
// that they should have defined luna_main() instead. If not, good for them: linker errors!
|
2023-04-13 15:04:59 +00:00
|
|
|
__attribute__((weak)) int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
g_argc = argc;
|
|
|
|
g_argv = argv;
|
|
|
|
|
|
|
|
int result;
|
|
|
|
bool ok = luna_main(argc, argv).try_set_value_or_error(result, errno);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
perror(g_argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|