|
Banjo API 1.1.0-alpha
Low-level C99 game development API
|
Macros | |
| #define | BJ_NO_AUTOMAIN |
| #define | BJ_AUTOMAIN |
| #define | BJ_MAIN_NOIMPL |
Functions | |
| int | bj_main (int argc, char *argv[]) |
| int | bj_call_main (int argc, char *argv[], int(*function)(int argc, char *argv[])) |
Write a regular int main(...), include <banjo/main.h>, and Banjo provides whatever platform entry point the target actually wants.
On Linux and macOS, int main(int argc, char* argv[]) is the entry point as you wrote it. On Windows, the OS may want WinMain for GUI programs, and argv arrives in the system locale rather than UTF-8. On Emscripten the JavaScript host calls main and then expects you to register a per-tick callback. Writing one int main(...) and expecting it to work on every platform needs a little glue.
<banjo/main.h> is that glue for standard-mode programs: short programs that fit in one main body, do their work, and return. On Windows, Emscripten and iOS, where BJ_AUTOMAIN is defined, the header emits a real main / WinMain, then renames your main to bj_main (via #define main bj_main); that entry point converts the arguments to UTF-8 on Windows and forwards to your bj_main. On the other platforms the header leaves your main as the entry point.
For long-running interactive programs (windows, animation, audio), use Application instead. Its callback model handles the platforms that own the run loop (Emscripten, future iOS) without per-platform #ifdefs in user code.
Define BJ_NO_AUTOMAIN before including the header to keep main as you wrote it; Banjo emits no wrapper.
| #define BJ_AUTOMAIN |
| #define BJ_MAIN_NOIMPL |
Internal flag that keeps the declarations without the entry point.
Banjo's own src/main.c defines it before including the header, to implement bj_call_main without emitting a main. Programs do not define it.
| #define BJ_NO_AUTOMAIN |
Opt out of Banjo's automatic main shim.
Define this macro before including <banjo/main.h> to keep main() exactly as you wrote it. Banjo will not emit any wrapper. Useful when you have your own platform-specific entry handling.
| int bj_call_main | ( | int | argc, |
| char * | argv[], | ||
| int(* | function )(int argc, char *argv[]) ) |
Forward into the user-supplied bj_main from a platform stub.
Called by the platform entry point that BJ_AUTOMAIN emits. On Windows this converts the UTF-16 command line into a UTF-8 argv before invoking function. On other platforms it forwards the argv it was given.
| argc | Argument count. |
| argv | Argument vector, given to function as is, NULL included (ignored on Windows). |
| function | The user's main, typically bj_main, or NULL, which runs nothing. |
function, or -1 without one.
|
extern |
The user's main(), after Banjo renames it.
You write int main(int argc, char* argv[]); the header's #define main bj_main rewrites it into this symbol. Banjo's emitted platform stub then forwards to it through bj_call_main.