1package plugin
2
3import (
4 "log"
5
6 lua "github.com/yuin/gopher-lua"
7)
8
9// registerAPI registers the "matcha" module into the Lua VM.
10func (m *Manager) registerAPI() {
11 L := m.state
12
13 mod := L.RegisterModule("matcha", map[string]lua.LGFunction{
14 "on": m.luaOn,
15 "log": m.luaLog,
16 "notify": m.luaNotify,
17 "set_status": m.luaSetStatus,
18 })
19
20 L.SetField(mod, "_VERSION", lua.LString("0.1.0"))
21}
22
23// matcha.on(event, callback) — register a hook callback.
24func (m *Manager) luaOn(L *lua.LState) int {
25 event := L.CheckString(1)
26 fn := L.CheckFunction(2)
27 m.registerHook(event, fn)
28 return 0
29}
30
31// matcha.log(msg) — log a message to stderr.
32func (m *Manager) luaLog(L *lua.LState) int {
33 msg := L.CheckString(1)
34 log.Printf("[plugin] %s", msg)
35 return 0
36}
37
38// matcha.set_status(area, text) — set a persistent status string for a view area.
39// Valid areas: "inbox", "composer", "email_view".
40func (m *Manager) luaSetStatus(L *lua.LState) int {
41 area := L.CheckString(1)
42 text := L.CheckString(2)
43 m.statuses[area] = text
44 return 0
45}
46
47// matcha.notify(msg [, seconds]) — show a temporary notification in the TUI.
48// The optional second argument sets the display duration in seconds (default 2).
49func (m *Manager) luaNotify(L *lua.LState) int {
50 m.pendingNotification = L.CheckString(1)
51 m.pendingDuration = float64(L.OptNumber(2, 2))
52 return 0
53}