Documentation
¶
Overview ¶
Package luaplugin provides a Lua 5.1 scripting engine for cliamp plugins. Each plugin runs in an isolated GopherLua VM. Plugins are loaded from ~/.config/cliamp/plugins/*.lua at startup.
Index ¶
- Constants
- func Sandbox(L *lua.LState)
- type ControlProvider
- type KeyBinding
- type Manager
- func (m *Manager) Close()
- func (m *Manager) CommandList() []string
- func (m *Manager) DestroyVis(name string)
- func (m *Manager) Emit(event string, data map[string]any)
- func (m *Manager) EmitCommand(pluginName, cmdName string, args []string) (string, error)
- func (m *Manager) EmitKey(key string) bool
- func (m *Manager) EmitSync(event string, data map[string]any)
- func (m *Manager) HasHook(event string) bool
- func (m *Manager) HasHooks() bool
- func (m *Manager) InitVis(name string, rows, cols int)
- func (m *Manager) KeyBindings() []KeyBinding
- func (m *Manager) PluginCount() int
- func (m *Manager) RenderVis(name string, bands [10]float64, rows, cols int, frame uint64) string
- func (m *Manager) SetControlProvider(cp ControlProvider)
- func (m *Manager) SetReservedKeys(keys map[string]bool)
- func (m *Manager) SetStateProvider(sp StateProvider)
- func (m *Manager) SetUIProvider(up UIProvider)
- func (m *Manager) Visualizers() []string
- type Plugin
- type QueueEntry
- type StateProvider
- type UIProvider
Constants ¶
const ( EventAppStart = "app.start" EventAppQuit = "app.quit" EventPlaybackState = "playback.state" EventTrackChange = "track.change" EventTrackScrobble = "track.scrobble" EventPlayerSeek = "player.seek" // data: position, duration (seconds) EventPlayerVolume = "player.volume" // data: db EventPlayerEQ = "player.eq" // data: bands (10-array), preset EventPlayerMode = "player.mode" // data: shuffle (bool), repeat ("Off"/"All"/"One") EventQueueChange = "queue.change" // data: count, index, queued )
Event name constants.
const ( PermControl = "control" PermExec = "exec" PermKeymap = "keymap" )
Permission strings declared via plugin.register({ permissions = {...} }). Kept as named constants so the guard call sites and docs don't drift.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ControlProvider ¶
type ControlProvider struct {
SetVolume func(db float64)
SetSpeed func(ratio float64)
SetEQBand func(band int, db float64)
ToggleMono func()
TogglePause func()
Stop func()
Seek func(secs float64)
SetEQPreset func(name string, bands *[10]float64) // injected via prog.Send
Next func() // injected via prog.Send
Prev func() // injected via prog.Send
// Queue mutators, all injected via prog.Send so the model's Update loop
// applies them and keeps derived state (cursor, current index) consistent.
QueueAdd func(path string) // resolve path/URL and append
QueueJump func(index int) // make index current and play it
QueueRemove func(index int) // remove track at index
QueueMove func(from, to int) // reorder
}
ControlProvider supplies write access to player controls. Only available to plugins that declare permissions = {"control"}.
type KeyBinding ¶
KeyBinding describes a plugin-registered keybinding for the Ctrl+K overlay.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns all loaded plugins and dispatches events to them.
func New ¶
New scans the plugin directory and loads all .lua files. pluginCfg maps plugin names to their [plugins.<name>] config keys. Returns a Manager (possibly with 0 plugins) and any non-fatal load error.
func (*Manager) Close ¶
func (m *Manager) Close()
Close fires the "app.quit" event synchronously and shuts down all Lua VMs.
func (*Manager) CommandList ¶
CommandList returns a flat list of "<plugin> <command>" strings. Used by `cliamp plugin commands`. Order is unspecified.
func (*Manager) DestroyVis ¶
DestroyVis calls a Lua visualizer's destroy() if it exists.
func (*Manager) Emit ¶
Emit dispatches an event to all plugins that registered for it. Each callback runs in its own goroutine with a timeout. The plugin's mutex serializes all LState access so concurrent events are safe.
func (*Manager) EmitCommand ¶
EmitCommand dispatches a plugin command invoked over IPC and blocks up to commandTimeout for the handler to return a result. A missing plugin/command returns ("", err); a handler error returns ("", err); success returns (result, nil). The result is whatever the handler returned as a string (nil or false stringifies to "").
func (*Manager) EmitKey ¶
EmitKey invokes every plugin callback registered for the given key string. Returns true if at least one callback fired. Called by the UI's main key dispatcher for keys the core doesn't handle.
func (*Manager) EmitSync ¶
EmitSync dispatches an event synchronously, blocking until all callbacks finish. Used during shutdown to ensure all handlers complete before LStates are closed.
func (*Manager) HasHook ¶
HasHook reports whether any plugin registered for a specific event. Callers use this to skip building event payloads (and any locks they require) when no plugin is listening for that particular event.
func (*Manager) KeyBindings ¶
func (m *Manager) KeyBindings() []KeyBinding
KeyBindings returns a snapshot of every plugin-registered keybinding that has a description, sorted by key for stable overlay ordering. Bindings registered without a description are omitted — plugins can opt out of surfacing a key simply by skipping the description argument.
Called once per Ctrl+K overlay open, so the sort cost is noise.
func (*Manager) PluginCount ¶
PluginCount returns the number of loaded plugins.
func (*Manager) RenderVis ¶
RenderVis calls a Lua visualizer's render(bands, frame) and returns the terminal text. On error, the previous frame is reused.
func (*Manager) SetControlProvider ¶
func (m *Manager) SetControlProvider(cp ControlProvider)
SetControlProvider sets the function pointers for player control. Only plugins with permissions = {"control"} can use these.
func (*Manager) SetReservedKeys ¶
SetReservedKeys records the set of keys owned by cliamp's core UI. Plugins attempting to bind one of these keys get a logged warning and their bind call returns false. Called once during startup from main.go.
func (*Manager) SetStateProvider ¶
func (m *Manager) SetStateProvider(sp StateProvider)
SetStateProvider sets the function pointers used by the Lua API to query live player/playlist state.
func (*Manager) SetUIProvider ¶
func (m *Manager) SetUIProvider(up UIProvider)
SetUIProvider sets the function pointers for UI output (status messages).
func (*Manager) Visualizers ¶
Visualizers returns the names of all Lua visualizer plugins.
type Plugin ¶
type Plugin struct {
Name string
Version string
Description string
Type string // "hook" or "visualizer"
L *lua.LState
// contains filtered or unexported fields
}
Plugin represents a single loaded Lua plugin.
type QueueEntry ¶
type QueueEntry struct {
Title string
Artist string
Album string
Path string
Index int
Queued bool
}
QueueEntry is one track in the playlist as exposed to plugins via cliamp.queue.list(). Index is 0-based and matches CurrentIndex; Queued is true when the track sits in the explicit play-next queue.
type StateProvider ¶
type StateProvider struct {
PlayerState func() string // "playing", "paused", "stopped"
Position func() float64 // seconds
Duration func() float64 // seconds
Volume func() float64 // dB
Speed func() float64 // ratio (1.0 = normal)
Mono func() bool
RepeatMode func() string // "off", "all", "one"
Shuffle func() bool
EQBands func() [10]float64
TrackTitle func() string
TrackArtist func() string
TrackAlbum func() string
TrackGenre func() string
TrackYear func() int
TrackNumber func() int
TrackPath func() string
TrackIsStream func() bool
TrackDuration func() int // seconds
PlaylistCount func() int
CurrentIndex func() int // 0-based
QueueList func() []QueueEntry // full playlist in play order
}
StateProvider supplies read-only access to player/playlist state. Functions are set by the caller after model construction so the Lua API can query live state without importing the ui package.
type UIProvider ¶
type UIProvider struct {
ShowMessage func(text string, duration time.Duration) // injected via prog.Send
}
UIProvider supplies callbacks that surface plugin output in the TUI. Not permission-gated — these are low-risk, output-only operations.