Skip to content

@this and receivers

CL++ is not C++. There is no Player*, no ->, and no this->x. Inside a method definition Class::Method, @ is the receiver sigil.

WriteLuau
@thisself
@janitorself.janitor
@coinsself.coins
hello.Greet(player)hello:Greet(player)
other.Register(@this)other:Register(self)

Declare the type in a .clh. Implement methods with Class::Method in a .clp / .clpp. void init() holds one service object and a local Janitor.

void CombatServer::BindPart(BasePart part) {
@janitor.Add(part, "Destroy");
other.Register(@this);
}
void Wallet::Add(int n) {
@coins = coins + n;
post("wallet " .: @coins);
}

init does not use @this. It constructs the service and captures it in the ~>Connect callback.

void init() {
Players players = GetService<Players>();
LeaderstatsServer leaderstatsServer;
Janitor janitor = new Janitor();
leaderstatsServer.janitor = janitor;
for (Player player in players.GetPlayers()) {
leaderstatsServer.PlayerEntered(player);
}
players.PlayerAdded~>Connect(func (Player playerEntered) {
leaderstatsServer.PlayerEntered(playerEntered);
});
}

See syntax for the operator table, and Janitor for @janitor plus the library.