plugin

package
v0.0.0-...-2f1a261 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

pkg/plugin/plugin.go Plugin system for loading native Go plugins at runtime.

Plugins are Go shared libraries (.so on Linux/macOS) that implement the Plugin interface. They can export functions, variables, and other values to xxlang code.

Usage from xxlang:

import "plugin/myplugin"
myplugin.hello()

Building a plugin:

go build -buildmode=plugin -o myplugin.so myplugin.go

pkg/plugin/plugin_native.go Native plugin loading for supported platforms (Linux, macOS, FreeBSD).

Index

Constants

This section is empty.

Variables

View Source
var Registry = struct {
	sync.RWMutex
	plugins map[string]Plugin
}{
	// contains filtered or unexported fields
}

Registry tracks loaded plugins. It is safe for concurrent use.

Functions

func Has

func Has(name string) bool

Has checks if a plugin is registered.

func List

func List() []string

List returns all registered plugin names.

func Register

func Register(p Plugin)

Register registers a plugin with the registry. This is typically called from a plugin's init() function.

func ToModule

func ToModule(p Plugin) *objects.Module

ToModule converts a Plugin to an objects.Module.

Types

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader handles loading .so plugin files.

func NewLoader

func NewLoader() *Loader

NewLoader creates a new plugin loader with default search paths.

func (*Loader) AddPath

func (l *Loader) AddPath(path string)

AddPath adds a search path for plugins.

func (*Loader) Load

func (l *Loader) Load(name string) (Plugin, error)

Load loads a plugin by name. It first checks the registry, then searches for a .so file. Returns the plugin and any error encountered.

Note: Go's plugin package only works on Linux, macOS, and FreeBSD. On Windows, this will return an error.

func (*Loader) Paths

func (l *Loader) Paths() []string

Paths returns the current search paths.

func (*Loader) SetPaths

func (l *Loader) SetPaths(paths []string)

SetPaths sets the search paths for plugins.

type Plugin

type Plugin interface {
	// Name returns the plugin name (used as plugin/name in imports).
	// This should match the filename (without .so extension).
	Name() string

	// Exports returns the module's exported symbols.
	// The map keys are the names accessible from xxlang code.
	Exports() map[string]objects.Object
}

Plugin is the interface that native plugins must implement. Plugins are loaded from .so files and register their exports through this interface.

func Get

func Get(name string) (Plugin, bool)

Get retrieves a plugin from the registry. Returns the plugin and true if found, nil and false otherwise.

Jump to

Keyboard shortcuts

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