pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.61k stars 519 forks source link

How to check either editor is a valid object #1054

Closed moteus closed 4 years ago

moteus commented 4 years ago

I have a plugin with the next functions

local _editor
Package.onEditorUpdateUI = function(self, editor, event)
    if bit.band(event:GetUpdated(), wxstc.wxSTC_UPDATE_SELECTION) > 0 then
        _editor = editor
    end
end

Package.onIdle = function(self)
    if not _editor then return end
    local editor = _editor
    _editor = false
    local color = editor:GetCaretLineBackground()

And some time I got error like attempt to index local 'editor' (a userdata value) This happen when I close editors quite fast. Is there any way to check either editor can be used?

pkulchenko commented 4 years ago

Yes, you can use ide:IsValidCtrl(editor); it's used in several places in event handlers.