Allow plugins to add their own runtime files

This commit is contained in:
Zachary Yedidia
2016-09-16 11:02:10 -04:00
parent f7295a25d8
commit 149fea8b76
5 changed files with 23 additions and 5 deletions

View File

@@ -319,6 +319,7 @@ func main() {
// Extension Files
L.SetGlobal("ReadRuntimeFile", luar.New(L, PluginReadRuntimeFile))
L.SetGlobal("ListRuntimeFiles", luar.New(L, PluginListRuntimeFiles))
L.SetGlobal("AddRuntimeFile", luar.New(L, PluginAddRuntimeFile))
LoadPlugins()

View File

@@ -137,8 +137,6 @@ func LoadPlugins() {
continue
}
loadedPlugins = append(loadedPlugins, pluginName)
} else if f.Name() == "help.md" {
AddRuntimeFile(FILE_Help, namedFile{realFile(fullPath), pluginName})
}
}
}

View File

@@ -2,6 +2,7 @@ package main
import (
"io/ioutil"
"os"
"path"
"path/filepath"
)
@@ -142,3 +143,13 @@ func PluginListRuntimeFiles(fileType string) []string {
}
return result
}
func PluginAddRuntimeFile(plugin, filetype, path string) {
fullpath := configDir + "/plugins/" + plugin + "/" + path
if _, err := os.Stat(fullpath); err == nil {
AddRuntimeFile(filetype, realFile(fullpath))
} else {
fullpath = "runtime/plugins/" + plugin + "/" + path
AddRuntimeFile(filetype, assetFile(fullpath))
}
}

File diff suppressed because one or more lines are too long