Skip to content

void init()

Script entry

Script / LocalScript entry point. CL++ has no int main().

void init() {
// ...
}

None.

void.

init() (called at the end of the file)

Only Scripts and LocalScripts run init() at the bottom of the emitted file. Untagged .clpp files are ModuleScripts: they return the table of Class:: methods and must not rely on init as a Roblox entry.

Construct one service object in init() and close over it from lambdas — that is the game singleton.

In init(), a synthetic __janitor is created and also game:BindToClose.

#include <clpp/roblox.clh>
void init() {
Players players = GetService<Players>();
post("ready");
}

Emits:

local players: Players = game:GetService("Players")
print("ready")
init()

struct · lambda · operator-janitor