ludic/annot-public.html
2026-09-17 22:10:03 +00:00

43 lines
No EOL
2.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@Public — Ludic</title>
<meta name="description" content="Promote a lifecycle hook to a public event other modules can listen for.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#annotations">Annotations</a> <span>›</span> <span class="here">@Public</span></div>
<div class="item-head">
<span class="kind-badge kind-annotation">annotation</span>
<h1 id="top">@Public</h1>
</div>
<code class="sig">@Public @OnSpawn(Model) handler … { … }</code>
<div class="desc"><p><code>@Public</code> stacks in front of a lifecycle hook to also emit a well-named event at the same moment the hook fires, so other modules (or mods) can react without touching the original code. It turns a private hook into a public seam: <code>@Public @OnSpawn(Model)</code> emits <code>model_&lt;Model&gt;_spawn</code>, <code>@OnDespawn</code> emits <code>model_&lt;Model&gt;_despawn</code>, the property hooks emit <code>prop_&lt;Property&gt;_attach</code>/<code>_detach</code>/<code>_enable</code>/<code>_disable</code>, and <code>@OnStart</code>/<code>@OnQuit</code> emit <code>program_start</code>/<code>program_quit</code>. This is the same lowering the event system uses, so anyone can <code>@On</code> the generated event to extend behavior at that lifecycle point. Add it when a hook marks an extension point you want to keep open across a modular codebase.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program PublicSpawn {
property Health { current: int = 0, maximum: int = 100 }
model Enemy { Health }
@Public @OnSpawn(Enemy) handler InitEnemy { # also emits model_Enemy_spawn
Health.current = Health.maximum
}
@On(model_Enemy_spawn) handler AnnounceEnemy { # another module hooks the public event
print(1) # 1 — reacts to every Enemy spawn
}
handler SpawnWave phase Start {
spawn Enemy { Health { current: 0, maximum: 100 } }
}
}</pre></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>