Documentation
¶
Index ¶
- Constants
- func Logger(ctx context.Context) logger.Logger
- func NewControlLibrary(manager *Manager) *object.Library
- func NormalizeLibraryName(name string) string
- func RegisterLibraries(registrar Registrar, manager *Manager)
- func Release(obj object.Object) error
- func ReleaseWithContext(ctx context.Context, obj object.Object) error
- type Callback
- type CallbackRef
- type ClassSchema
- type Client
- func (c *Client) CallFunction(ctx context.Context, name string, args []Value, kwargs map[string]Value) (Value, error)
- func (c *Client) CallFunctionWithCallbacks(ctx context.Context, name string, args []Value, kwargs map[string]Value, ...) (Value, error)
- func (c *Client) CallMethod(ctx context.Context, objectID, method string, args []Value, ...) (Value, error)
- func (c *Client) CallMethodWithCallbacks(ctx context.Context, objectID, method string, args []Value, ...) (Value, error)
- func (c *Client) Close() error
- func (c *Client) DestroyObject(ctx context.Context, objectID string) error
- func (c *Client) Health() error
- func (c *Client) Metadata() Metadata
- func (c *Client) NewObject(ctx context.Context, class string, args []Value, kwargs map[string]Value) (*RemoteRef, error)
- func (c *Client) NewObjectWithCallbacks(ctx context.Context, class string, args []Value, kwargs map[string]Value, ...) (*RemoteRef, error)
- type ConstantSchema
- type FunctionSchema
- type Manager
- func (m *Manager) AddDir(dir string)
- func (m *Manager) Close() error
- func (m *Manager) Get(name string) (*Client, bool)
- func (m *Manager) Health() map[string]error
- func (m *Manager) List() []Metadata
- func (m *Manager) Load(ctx context.Context) error
- func (m *Manager) SetCrashHandler(handler func(name string, err error))
- func (m *Manager) SetLogger(log logger.Logger)
- func (m *Manager) Warnings() []string
- type Metadata
- type PropertySchema
- type RPCError
- type Registrar
- type RemoteRef
- type Schema
- type ScriptLibraryRegistrar
- type Server
- func (s *Server) Constant(name string, value any) *Server
- func (s *Server) RegisterClass(builder *object.ClassBuilder) *Server
- func (s *Server) RegisterFunc(name string, builder *object.FunctionBuilder) *Server
- func (s *Server) RegisterScriptClass(name string, source string) *Server
- func (s *Server) RegisterScriptFunc(name string, source string) *Server
- func (s *Server) Run() error
- func (s *Server) RunIO(input io.Reader, output io.Writer) error
- func (s *Server) Wrapper(name string, source string) *Server
- type Value
Constants ¶
const ( // ProtocolVersion is the JSON-RPC plugin protocol version supported by this host. ProtocolVersion = "1.0" // NamespacePrefix is the host-owned namespace for discovered plugin libraries. NamespacePrefix = "plugin." )
const ControlLibraryName = "scriptling.plugin"
const DefaultReleaseTimeout = 2 * time.Second
DefaultReleaseTimeout is used by Release and GC finalizers when no caller context is available. Use ReleaseWithContext for request-scoped cleanup.
Variables ¶
This section is empty.
Functions ¶
func Logger ¶ added in v0.11.0
Logger returns a call-scoped proxy to the manager's host logger. It uses ctx to find the active plugin call runtime, so plugin code should request it from functions, constructors, methods, or property accessors and should not store it globally. If ctx is not attached to an active plugin call, Logger returns a no-op logger.
func NewControlLibrary ¶
func NormalizeLibraryName ¶
NormalizeLibraryName returns name in the host-owned plugin namespace.
func RegisterLibraries ¶
Types ¶
type Callback ¶
Callback is a host callback passed into a plugin call. It is valid only until the outer plugin function, constructor, or method returns.
type CallbackRef ¶
type CallbackRef struct {
ID string `json:"id"`
}
CallbackRef identifies a callback valid during one outer plugin call.
type ClassSchema ¶
type ClassSchema struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Constructor FunctionSchema `json:"constructor,omitempty"`
Methods []FunctionSchema `json:"methods,omitempty"`
Properties []PropertySchema `json:"properties,omitempty"`
Source string `json:"source,omitempty"`
}
ClassSchema describes a plugin class and its methods.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CallFunction ¶
func (*Client) CallFunctionWithCallbacks ¶
func (*Client) CallMethod ¶
func (*Client) CallMethodWithCallbacks ¶
func (*Client) DestroyObject ¶
type ConstantSchema ¶
ConstantSchema describes a plugin constant.
type FunctionSchema ¶
type FunctionSchema struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Source string `json:"source,omitempty"`
}
FunctionSchema describes a plugin function or supplied wrapper source.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
NewManager creates an empty plugin manager. If log is not nil, plugin log records emitted through Logger(ctx) are forwarded to it. If crashHandler is provided, it is called when a loaded plugin process exits unexpectedly.
func (*Manager) AddDir ¶
AddDir adds a directory whose executable files should be loaded as plugins.
func (*Manager) Health ¶
Health returns loaded plugins whose process or stdio transport is unhealthy.
func (*Manager) SetCrashHandler ¶
SetCrashHandler installs a callback for loaded plugin processes that exit unexpectedly. The handler is not called for normal manager shutdown.
type Metadata ¶
type Metadata struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Transport string `json:"transport,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
Schema Schema `json:"schema"`
}
Metadata describes a loaded plugin library.
type PropertySchema ¶ added in v0.11.0
type PropertySchema struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Settable bool `json:"settable,omitempty"`
}
PropertySchema describes a plugin class property.
type RemoteRef ¶
type RemoteRef struct {
Library string `json:"library"`
Class string `json:"class"`
ID string `json:"id"`
}
RemoteRef identifies an object stored in a plugin process.
type Schema ¶
type Schema struct {
Functions []FunctionSchema `json:"functions"`
Classes []ClassSchema `json:"classes"`
Constants []ConstantSchema `json:"constants"`
}
Schema describes functions, classes, and constants exposed by a plugin.
type ScriptLibraryRegistrar ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) RegisterClass ¶
func (s *Server) RegisterClass(builder *object.ClassBuilder) *Server
func (*Server) RegisterFunc ¶
func (s *Server) RegisterFunc(name string, builder *object.FunctionBuilder) *Server
func (*Server) RegisterScriptClass ¶
func (*Server) RegisterScriptFunc ¶
type Value ¶
type Value struct {
Type string `json:"type"`
Value any `json:"value,omitempty"`
Items []Value `json:"items,omitempty"`
Entries map[string]Value `json:"entries,omitempty"`
Remote *RemoteRef `json:"remote,omitempty"`
Callback *CallbackRef `json:"callback,omitempty"`
}
Value is the JSON-RPC transport representation of Scriptling values.