zplugin

package
v0.0.0-alpha.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAssert represents type assertion such like value.(T) failed.
	ErrAssert = errors.New("zplugin: failed to assert type")
)

Functions

func Lookup

func Lookup(path, symName string) (plugin.Symbol, error)

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

func LookupAll(path string, symNames ...string) (map[string]plugin.Symbol, error)

LookupAll reads Go plugin from the given path and lookups all given symbol names. See the comment on Lookup.

func Use

func Use[T any](path, symName string) (plugin.Symbol, T, error)

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

func WithTestOpenFunc(f func(path string) (Lookupper, error)) (done func())

WithTestOpenFunc replaces plugin.Open func for testing. Note that this changes global state.

Types

type Lookupper

type Lookupper interface {
	Lookup(symName string) (plugin.Symbol, error)
}

Lookupper lookups exported package symbols. plugin.Plugin implements the interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL