-
-
Notifications
You must be signed in to change notification settings - Fork 0
API Loader Plugins
3cxc edited this page Sep 13, 2026
·
2 revisions
public abstract class Plugin
{
public HostApiTable Api { get; }
public abstract string Name { get; }
public abstract string Description { get; }
public abstract string Author { get; }
public virtual Version? Version { get; }
public abstract Version RequiredApiVersion { get; }
protected abstract void OnStart();
public abstract void OnStop();
}Base class for all plugins.
-
Module load —
__GeneratedModuleInit(marked[ModuleInitializer]) callsSetPluginInfo(new YourPlugin())so metadata is available beforeOnInit. -
OnInit— the source generator emits this export. It creates the plugin instance and callsPlugin.Initialize(hostApiTablePtr, instance), which:- Populates
PluginContext.CurrentApi. - Calls
OnStart().
- Populates
-
OnStopexport — the generator emits__GeneratedOnStop(exported asOnStop) which calls the instance'sOnStop()and clears the reference.
public partial class MyPlugin : Plugin // ← partial is mandatory
{
public override string Name => "MyPlugin";
public override string Description => "...";
public override string Author => "...";
public override Version RequiredApiVersion => new(1, 0, 0);
protected override void OnStart() { /* ... */ }
public override void OnStop() { /* ... */ }
}public static class PluginContext
{
public static HostApiTable CurrentApi { get; internal set; }
}Global accessor for the host's API table. Set once during Initialize, read by every generated API method. Plugins should not modify it.