Autoclose plugin support

This commit is contained in:
Zachary Yedidia
2019-08-02 14:48:59 -07:00
parent a47e1f0ca5
commit e3ae38e54a
8 changed files with 179 additions and 1096 deletions

View File

@@ -17,6 +17,7 @@ func LoadAllPlugins() {
}
// RunPluginFn runs a given function in all plugins
// returns an error if any of the plugins had an error
func RunPluginFn(fn string, args ...lua.LValue) error {
var reterr error
for _, p := range Plugins {
@@ -31,6 +32,33 @@ func RunPluginFn(fn string, args ...lua.LValue) error {
return reterr
}
// RunPluginFnBool runs a function in all plugins and returns
// false if any one of them returned false
// also returns an error if any of the plugins had an error
func RunPluginFnBool(fn string, args ...lua.LValue) (bool, error) {
var reterr error
retbool := true
for _, p := range Plugins {
if !p.IsEnabled() {
continue
}
val, err := p.Call(fn, args...)
if err == ErrNoSuchFunction {
continue
}
if err != nil {
reterr = errors.New("Plugin " + p.Name + ": " + err.Error())
continue
}
if v, ok := val.(lua.LBool); !ok {
reterr = errors.New(p.Name + "." + fn + " should return a boolean")
} else {
retbool = retbool && bool(v)
}
}
return retbool, reterr
}
type Plugin struct {
Name string // name of plugin
Info RuntimeFile // json file containing info