Skip to content

API Loader

3cxc edited this page Sep 13, 2026 · 2 revisions

NativePluginKit.Loader

Plugin loading and lifecycle management.


PluginLoader

public unsafe class PluginLoader
{
    public PluginLoader(Action<string> logAction,
                        HostApiTable apiTable,
                        Version apiVersion);

    public HostApiTable Api { get; }
    public Action<string> LogWriter { get; }
    public Version CurrentApiVersion { get; }

    public bool LoadPlugin(string dllPath);
    public void LoadPluginsFromDirectory(string directoryPath);
    public void UnloadAll();
}

LoadPlugin(string dllPath)

Loads a single plugin DLL/SO/DYLIB.

Steps performed:

  1. LoadLibrary (Windows) or dlopen (Unix).
  2. Read GetPluginInfo → PluginInfo.
  3. Reject if the plugin requests an incompatible API version.
  4. Read OnInit and invoke it with a pointer to the HostApiTable.
  5. Record the handle for later UnloadAll.

The module handle is kept alive for the host's lifetime.

LoadPluginsFromDirectory(string directoryPath)

Enumerates *.dll / *.so / *.dylib (based on the compile-time platform) and calls LoadPlugin for each. Silently returns if the directory does not exist.

UnloadAll()

Iterates every loaded plugin:

  1. Calls the exported OnStop if present.
  2. FreeLibrary / dlclose.

After UnloadAll, the plugin loader is empty and can be reused.

Clone this wiki locally