- // Load all the plugin stuff
- // We give plugins access to a bunch of variables here which could be useful to them
- L.SetGlobal("OS", luar.New(L, runtime.GOOS))
- L.SetGlobal("tabs", luar.New(L, tabs))
- L.SetGlobal("curTab", luar.New(L, curTab))
- L.SetGlobal("messenger", luar.New(L, messenger))
- L.SetGlobal("GetOption", luar.New(L, GetOption))
- L.SetGlobal("AddOption", luar.New(L, AddOption))
- L.SetGlobal("SetOption", luar.New(L, SetOption))
- L.SetGlobal("SetLocalOption", luar.New(L, SetLocalOption))
- L.SetGlobal("BindKey", luar.New(L, BindKey))
- L.SetGlobal("MakeCommand", luar.New(L, MakeCommand))
- L.SetGlobal("CurView", luar.New(L, CurView))
- L.SetGlobal("IsWordChar", luar.New(L, IsWordChar))
- L.SetGlobal("HandleCommand", luar.New(L, HandleCommand))
- L.SetGlobal("HandleShellCommand", luar.New(L, HandleShellCommand))
- L.SetGlobal("GetLeadingWhitespace", luar.New(L, GetLeadingWhitespace))
- L.SetGlobal("MakeCompletion", luar.New(L, MakeCompletion))
- L.SetGlobal("NewBuffer", luar.New(L, NewBufferFromString))
- L.SetGlobal("RuneStr", luar.New(L, func(r rune) string {
- return string(r)
- }))
- L.SetGlobal("Loc", luar.New(L, func(x, y int) Loc {
- return Loc{x, y}
- }))
- L.SetGlobal("WorkingDirectory", luar.New(L, os.Getwd))
- L.SetGlobal("JoinPaths", luar.New(L, filepath.Join))
- L.SetGlobal("DirectoryName", luar.New(L, filepath.Dir))
- L.SetGlobal("configDir", luar.New(L, configDir))
- L.SetGlobal("Reload", luar.New(L, LoadAll))
- L.SetGlobal("ByteOffset", luar.New(L, ByteOffset))
- L.SetGlobal("ToCharPos", luar.New(L, ToCharPos))
-
- // Used for asynchronous jobs
- L.SetGlobal("JobStart", luar.New(L, JobStart))
- L.SetGlobal("JobSpawn", luar.New(L, JobSpawn))
- L.SetGlobal("JobSend", luar.New(L, JobSend))
- L.SetGlobal("JobStop", luar.New(L, JobStop))
-
- // Extension Files
- L.SetGlobal("ReadRuntimeFile", luar.New(L, PluginReadRuntimeFile))
- L.SetGlobal("ListRuntimeFiles", luar.New(L, PluginListRuntimeFiles))
- L.SetGlobal("AddRuntimeFile", luar.New(L, PluginAddRuntimeFile))
- L.SetGlobal("AddRuntimeFilesFromDirectory", luar.New(L, PluginAddRuntimeFilesFromDirectory))
- L.SetGlobal("AddRuntimeFileFromMemory", luar.New(L, PluginAddRuntimeFileFromMemory))
-
- // Access to Go stdlib
- L.SetGlobal("import", luar.New(L, Import))
-
- jobs = make(chan JobFunction, 100)
- events = make(chan tcell.Event, 100)
- autosave = make(chan bool)
-
- LoadPlugins()
-
- for _, t := range tabs {
- for _, v := range t.views {
- for pl := range loadedPlugins {
- _, err := Call(pl+".onViewOpen", v)
- if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
- TermMessage(err)
- continue
- }
- }
- }
- }