Skip to content

Jomy10/Plugins

Repository files navigation

Plugins

examples | documentation


A simple plugin framework for Swift applications.

Load dynamic libraries and call their functions dynamically.

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.

About

Plugin framework for Swift applications

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages