Skip to content

Commit 54ba3cd

Browse files
committed
Make PluginCB() a variadic function
So that we can pass extra arguments to bufpane callbacks easily, by passing them directly to PluginCB().
1 parent 97b5e35 commit 54ba3cd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

internal/action/bufpane.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,16 @@ func (h *BufPane) ResizePane(size int) {
321321
}
322322

323323
// PluginCB calls all plugin callbacks with a certain name and displays an
324-
// error if there is one and returns the aggregate boolean response
325-
func (h *BufPane) PluginCB(cb string) bool {
326-
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h))
324+
// error if there is one and returns the aggregate boolean response.
325+
// The bufpane is passed as the first argument to the callbacks,
326+
// optional args are passed as the next arguments.
327+
func (h *BufPane) PluginCB(cb string, args ...interface{}) bool {
328+
largs := []lua.LValue{luar.New(ulua.L, h)}
329+
for _, a := range args {
330+
largs = append(largs, luar.New(ulua.L, a))
331+
}
332+
333+
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, largs...)
327334
if err != nil {
328335
screen.TermMessage(err)
329336
}

0 commit comments

Comments
 (0)