Documentation
¶
Index ¶
- Variables
- func Lookup(path, symName string) (plugin.Symbol, error)
- func LookupAll(path string, symNames ...string) (map[string]plugin.Symbol, error)
- func Use[T any](path, symName string) (plugin.Symbol, T, error)
- func WithTestOpenFunc(f func(path string) (Lookupper, error)) (done func())
- type Lookupper
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAssert represents type assertion such like value.(T) failed. ErrAssert = errors.New("zplugin: failed to assert type") )
Functions ¶
func Lookup ¶
Lookup reads Go plugin from the path and lookups symbol by the name. It is short for plugin.Open and plugin.Plugin.Lookup.
For example, a plugin defined as
package main import "fmt" func MyFunc() { fmt.Printf("Hello, number %d\n", V) }
may be loaded with the Lookup function and then the exported package symbols MyFunc can be accessed
sym, err := zplugin.Lookup("plugin_name.so", "MyFunc") if err != nil { panic(err) } myFunc := sym.(func()) // Now MyFunc() is available with myFunc.
func LookupAll ¶
LookupAll reads Go plugin from the given path and lookups all given symbol names. See the comment on Lookup.
func Use ¶
Use reads Go plugin from the path and lookups symbol by the name. Then it also assert symbol into the type T. It is short for Lookup and type assertion.
For example, a plugin defined as
package main import "fmt" func MyFunc() { fmt.Printf("Hello, number %d\n", V) }
may be loaded with the Use function and then the exported package symbols MyFunc can be accessed
// MyFunc() is available with myFunc. myFunc, err := zplugin.Use[func()]("plugin_name.so", "MyFunc") if err != nil { panic(err) }
func WithTestOpenFunc ¶
WithTestOpenFunc replaces plugin.Open func for testing. Note that this changes global state.