From cb90efe5910a50b3d055c769d0a81a12058c90a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Wed, 10 Jul 2019 14:39:41 +0200 Subject: [PATCH] kod --- lua/luadev.lua | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lua/luadev.lua b/lua/luadev.lua index 4179833..dd30bda 100644 --- a/lua/luadev.lua +++ b/lua/luadev.lua @@ -102,19 +102,17 @@ local function dedent(str, leave_indent) return str end -local function ld_pcall(chunk) +local function ld_pcall(chunk, ...) local coro = coroutine.create(chunk) - local status, res = coroutine.resume(coro) - if status then - return true, res - else + local res = {coroutine.resume(coro, ...)} + if not res[1] then _G._errstack = coro -- if the only frame on the traceback is the chunk itself, skip the traceback if debug.getinfo(coro, 0,"f").func ~= chunk then - res = debug.traceback(coro, res, 0) + res[2] = debug.traceback(coro, res[2], 0) end - return false, res end + return unpack(res) end local function exec(str) @@ -154,12 +152,32 @@ local function start() open_win() end +local function err_wrap(cb) + return (function (...) + local res = {ld_pcall(cb, ...)} + if not res[1] then + open_win() + append_buf(res[2],"WarningMsg") + return nil + else + table.remove(res, 1) + return unpack(res) + end + end) +end + +local function schedule_wrap(cb) + return vim.schedule_wrap(err_wrap(cb)) +end + local mod = { create_buf=create_buf, start=start, exec=exec, print=luadev_print, - append_buf=append_buf + append_buf=append_buf, + err_wrap = err_wrap, + schedule_wrap = schedule_wrap, } -- TODO: export abstraction for autoreload