Contents

jomy10/plugins

Example

Plugin.swift

@_cdecl("loadPlugin")
public func loadPlugin(_ data: UnsafeMutablePointer) -> Int32 {
  print("Plugin was loaded!")
  return 0
}

@_cdecl("somePluginFunction")
public func somePluginFunction() {
  print("Called some library function")
}

Main.swift

let plugin = Plugin(name: "Plugin", location: URL.currentDirectory())
// output: Plugin was loaded!
typealias SomePluginFunction = @convention(c) () -> ()
let pluginFn: PluginFunction<SomePluginFunction> = plugin.loadFunction(name: "somePluginFunction")!
pluginFn.function()
// output: Called some library function

We can compile the above Plugin.swift file with Swift Package Manager by defining a library product for the Plugin target:

.library(
  name: "Plugin",
  type: .dynamic,
  targets: ["Plugin"]
)

More examples, see EXAMPLES.md.

Logging

The library also supports some basic logging using swift-log.

Package Metadata

Repository: jomy10/plugins

Default branch: master

README: README.md