plugin

package
v0.0.0-...-dbc11f2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package plugin provides a plugable infrastructure for native envel bindings Plugins are loaded when envel is started and can preload code to be exposed to the event loop / lua LState

Index

Constants

View Source
const SymbolName = "Plugin"

SymbolName defines the name of the symbol that should be exposed by all plugins and should implement the Plugin interface

Variables

View Source
var DefaultLoader = &defaultLoader{}

DefaultLoader is the default plugin loader used by LoadDirectory() and LoadFile()

Functions

func Register

func Register(name string, p Plugin)

Register registeres a new built-in plugin

Types

type Binding

type Binding interface {
	// Preload is called when the binding should preload itself into the provided
	// lua state. Note that this function may be called mutliple times with different
	// lua states. The plugin must NOT share objects between different states
	Preload(*lua.LState) error
}

Binding describes a plugin type that provides additional native bindings for envel

type Instance

type Instance interface {
	Plugin

	// Name returns the filename of the plugin
	Name() string

	// Path returns the path to the plugin file
	Path() string
}

Instance represents a loaded plugin

func Builtin

func Builtin() []Instance

Builtin returns a list of built-in plugins

func LoadDirectory

func LoadDirectory(path string) ([]Instance, error)

LoadDirectory loads all plugins from the given directory. It used DefaultLoader as the plugin Loader

func LoadFile

func LoadFile(path string) (Instance, error)

LoadFile loads an envel plugin from the given file. It uses DefaultLoader as the plugin Loader

type Loader

type Loader interface {
	// LoadDirectory loads all plugins from the given directory
	// If the specified path is a file, it should try to directly load the file
	LoadDirectory(path string) ([]Instance, error)

	// LoadFile loads an envel plugin from the given file
	LoadFile(path string) (Instance, error)
}

Loader provides methods for loading plugins

type Option

type Option func(p *pluginImpl)

Option defines the type of function that serves as a plugin option

func WithBinding

func WithBinding(b Binding) Option

WithBinding adds a new binding the the plugin This is a singular alias for WithBindings

func WithBindings

func WithBindings(b ...Binding) Option

WithBindings adds one or more bindings to the plugin

func WithInit

func WithInit(init func() error) Option

WithInit configures the init function to call when the plugin is loaded

type Plugin

type Plugin interface {
	// Init is called to initialize the plugin. It is called exactly once when
	// the plugin is loaded
	Init() error

	// Bindings should return a list of native lua bindings or nil if none are supported
	// by the plugin
	Bindings() []Binding
}

Plugin describes a plugin for envel

func New

func New(opts ...Option) Plugin

New creates a new plugin

Jump to

Keyboard shortcuts

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