Banjo API 1.1.0-alpha
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
#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[]))

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

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

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 71 of file main.h.

◆ BJ_MAIN_NOIMPL

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

Definition at line 80 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 62 of file main.h.

Function Documentation

◆ bj_call_main()

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.

Parameters
argcArgument count.
argvArgument vector, given to function as is, NULL included (ignored on Windows).
functionThe user's main, typically bj_main, or NULL, which runs nothing.
Returns
The value returned by function, or -1 without one.

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