diff --git a/README.md b/README.md index 0f3eca5..4f7f8af 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ package plugin internal fun createPlugin(): PumpkinPlugin = example.MyPlugin() ``` -This replaces the API's placeholder factory during consumer compilation. On the first exported callback, the API bridge constructs and caches your plugin instance. Later callbacks use the same instance. There is no need for `main()`, a top-level registration initializer, or a call to `registerPlugin(...)`. The package also supplies the generator-specific `PluginRootFunctionsExportsImpl` and `MetadataImpl` bridges. +This replaces the API's placeholder factory during consumer compilation. On the first exported callback, the API bridge constructs and caches your plugin instance. Later callbacks use the same instance. The package supplies the generator-specific `PluginRootFunctionsExportsImpl` and `MetadataImpl` bridges. ## Server compatibility diff --git a/api/src/wasmWasiMain/kotlin/plugin/PumpkinPlugin.kt b/api/src/wasmWasiMain/kotlin/plugin/PumpkinPlugin.kt index c8bb151..0ddde65 100644 --- a/api/src/wasmWasiMain/kotlin/plugin/PumpkinPlugin.kt +++ b/api/src/wasmWasiMain/kotlin/plugin/PumpkinPlugin.kt @@ -69,24 +69,20 @@ abstract class PumpkinPlugin { typealias PluginMetadata = Metadata.PluginMetadata -private var registeredPlugin: PumpkinPlugin? = null +private var pluginInstance: PumpkinPlugin? = null -/** Registers the plugin instance exported by this WebAssembly component. */ -fun registerPlugin(plugin: PumpkinPlugin) { - check(registeredPlugin == null) { "A Pumpkin plugin has already been registered." } - registeredPlugin = plugin -} - -private fun requirePlugin(): PumpkinPlugin = registeredPlugin ?: createPlugin().also { - registeredPlugin = it +private fun requirePlugin(): PumpkinPlugin = pluginInstance ?: createPlugin().also { + pluginInstance = it } private fun unsupportedCallback(name: String): T = error("PumpkinPlugin.$name has not been implemented.") /** - * WIT export bridge used by the generated bindings. Plugin authors use [PumpkinPlugin] and - * [registerPlugin] instead of implementing this generated interface directly. + * WIT export bridge used by the generated bindings. Plugin authors extend [PumpkinPlugin] + * and configure pumpkin.pluginClass. + * + * The generated bootstrap supplies the instance automatically. */ internal class PluginRootFunctionsExportsImpl { companion object : PluginRootFunctions.Exports {