diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/client.lua | 10 | ||||
-rw-r--r-- | script/plugin.lua | 20 |
2 files changed, 29 insertions, 1 deletions
diff --git a/script/client.lua b/script/client.lua index 12020fe5..92bb1327 100644 --- a/script/client.lua +++ b/script/client.lua @@ -168,6 +168,15 @@ function m.editText(uri, edits) }) end +local function hookPrint() + if TEST then + return + end + print = function (...) + m.logMessage('Log', ...) + end +end + function m.init(t) log.debug('Client init', util.dump(t)) m.info = t @@ -175,6 +184,7 @@ function m.init(t) m.client(t.clientInfo.name) nonil.disable() lang(LOCALE or t.locale) + hookPrint() end return m diff --git a/script/plugin.lua b/script/plugin.lua index 15c7c311..3dbb1b66 100644 --- a/script/plugin.lua +++ b/script/plugin.lua @@ -1,9 +1,19 @@ local config = require 'config' local util = require 'utility' +local client = require 'client' +local lang = require 'language' ---@class plugin local m = {} +function m.showError(err) + if m._hasShowedError then + return + end + m._hasShowedError = true + client.showMessage('Error', lang.script('PLUGIN_RUNTIME_ERROR', m.pluginPath, err)) +end + function m.dispatch(event, ...) if not m.interface then return false @@ -17,6 +27,8 @@ function m.dispatch(event, ...) tracy.ZoneEnd() if suc then return true, res1, res2 + else + m.showError(res1) end return false, res1 end @@ -45,13 +57,19 @@ function m.init() if not pluginLua then return end + m.pluginPath = pluginPath local env = setmetatable(m.interface, { __index = _ENV }) local f, err = load(pluginLua, '@'..pluginPath, "t", env) if not f then log.error(err) + m.showError(err) + return + end + local suc, err = xpcall(f, log.error, f) + if not suc then + m.showError(err) return end - xpcall(f, log.error, f) resetFiles() end |