Skip to content

Cluaupp — anonymous callbacks

This note is for Cluaupp: templates, snippets, generated .clpp, and tests that write CL++ source. The compile JSON contract (clpp api compile) did not change. The language did.

CL++ anonymous callbacks are now func (params) { }. The C++ capture list is gone.

players.PlayerAdded~>Connect(func (Player playerEntered) {
post("hello, " .: playerEntered.Name);
});
pcall(func () {
return 1;
});
func onCoinsChanged = func (int newValue) {
post(newValue);
};

Zero parameters still need the keyword and empty parens: func () { }.

These do not compile:

func [](Player player) { }
[]() { }
func []() { }

[] is only indexing (names[0], stats["Coins"], folder[childName]). It is not a lambda.

Cluaupp still receives ordinary Luau from clpp api compile. A janitor Connect stays a janitor Connect:

players.PlayerAdded~>Connect(func (Player playerEntered) {
post(playerEntered.Name);
});
janitor:Add(players.PlayerAdded:Connect(function(playerEntered: Player)
print(playerEntered.Name)
end), "Disconnect")

Manual connect (no Janitor) is ::Connect with the same func ( body.

The compiler requires:

func ( [params] ) { statements }
  • Keyword func (also the type).
  • () — parameter list may be empty.
  • {} — body. No ->.

Named functions are unchanged: void Greet(Player player) { }.

When Cluaupp prints accessors next to a callback, use the current table:

CL++Meaning
.Property and instance method (player.Name, player.Kick(), workspace.FindFirstChild("x"))
:Type on a name, or a protected (pcall) call (age: int, player:Kick())
::Static / class method definition / manual Connect
~>Connect / Once with Janitor
[]Index only

clpp api compile returns ok: false plus diagnostics[] when a file still has func [] / [](). The editor pack lints the same line:

use func (params) { } — CL++ does not use captures []

After shipping a new clpp, Cluaupp users need a language-pack refresh so Error Lens / CL++ Lens shows that message: clpp setup / clpp install, or copy editors/vscode into the editor extensions folder, then reload.

  1. Scaffold / init templates — every Connect, Once, OnChange, pcall, Vide/Fusion callback.
  2. Snippet generators — stop concatenating func []( or [](.
  3. Golden .clpp fixtures — rewrite to func (Type name) { }.
  4. Docs and UI copy that showed []() as “CL++ lambda”.
  5. Tests that asserted func [] still compiled — they should now expect failure.

The CompileRequest / CompileArtifact types in support/cluaupp.d.ts stay the same shape. Full CLI upgrade (0.7.0): Cluaupp 0.7.0 and Update Cluaupp.

func (…) · func · Connect · operators · JSON contract