Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
Main Entry Point
Collaboration diagram for Main Entry Point:

Macros

#define BJ_NO_AUTOMAIN
#define BJ_AUTOMAIN

Functions

int bj_main (int argc, char *argv[])
int bj_call_main (int argc, char *argv[], int(*function)(int argc, char *argv[]))

Detailed Description

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. The header renames your main to bj_main (via #define main bj_main) and, on platforms that need it, emits a real main / WinMain that converts arguments to UTF-8 and forwards to your bj_main.

#include <banjo/main.h>
int main(int argc, char* argv[]) {
(void)argc; (void)argv;
/* your program *&zwj;/
return 0;
}
int main(int argc, char *argv[])
Definition audio_pcm.c:177
Portable main() replacement with platform-aware entry shim.

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.

Opt-out

Define BJ_NO_AUTOMAIN before including the header to keep main as you wrote it; Banjo emits no wrapper.

Macro Definition Documentation

◆ BJ_AUTOMAIN

#define BJ_AUTOMAIN

Internal flag indicating Banjo emits the platform entry point.

Auto-defined on Windows, Emscripten, and iOS. Do not define it manually.

Definition at line 69 of file main.h.

◆ BJ_NO_AUTOMAIN

#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.

Definition at line 60 of file main.h.

Function Documentation

◆ bj_call_main()

int bj_call_main ( int argc,
char * argv[],
int(* function )(int argc, char *argv[]) )
extern

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.

Parameters
argcArgument count.
argvArgument vector (may be ignored on Windows).
functionThe user's main, typically bj_main.
Returns
The value returned by function.

◆ bj_main()

int bj_main ( int argc,
char * argv[] )
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.