Skip to content

Commit

Permalink
Add a lock for plugins to use if using async code
Browse files Browse the repository at this point in the history
Ref #1539
  • Loading branch information
zyedidia committed Jun 28, 2020
1 parent f5c6f66 commit 253281a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/micro/initlua.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/micro/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/lua/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"regexp"
"runtime"
"strings"
"sync"
"time"
"unicode/utf8"

Expand All @@ -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 {
Expand Down

0 comments on commit 253281a

Please sign in to comment.