Add a lock for plugins to use if using async code

Ref #1539
This commit is contained in:
Zachary Yedidia
2020-06-28 16:29:32 -04:00
parent f5c6f66c8f
commit 253281ae5e
3 changed files with 6 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ func luaImportMicro() *lua.LTable {
ulua.L.SetField(pkg, "Tabs", luar.New(ulua.L, func() *action.TabList {
return action.Tabs
}))
ulua.L.SetField(pkg, "Lock", luar.New(ulua.L, ulua.Lock))
return pkg
}

View File

@@ -17,6 +17,7 @@ import (
"github.com/zyedidia/micro/v2/internal/action"
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
"github.com/zyedidia/micro/v2/internal/shell"
"github.com/zyedidia/micro/v2/internal/util"
@@ -344,7 +345,9 @@ func main() {
// okay to be inefficient and run it via a function every time
// We do this so we can recover from panics without crashing the editor
for {
ulua.Lock.Lock()
DoEvent()
ulua.Lock.Unlock()
}
}

View File

@@ -15,6 +15,7 @@ import (
"regexp"
"runtime"
"strings"
"sync"
"time"
"unicode/utf8"
@@ -24,6 +25,7 @@ import (
)
var L *lua.LState
var Lock sync.Mutex
// LoadFile loads a lua file
func LoadFile(module string, file string, data []byte) error {