From 729073ec3619cde7c6be8102bc6e390f83d0dffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 9 Dec 2019 15:37:40 +0800 Subject: =?UTF-8?q?=E8=BF=87hover=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/core/hover/return.lua | 2 +- script-beta/utility.lua | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'script-beta') diff --git a/script-beta/core/hover/return.lua b/script-beta/core/hover/return.lua index a4d3b989..e10f9416 100644 --- a/script-beta/core/hover/return.lua +++ b/script-beta/core/hover/return.lua @@ -8,7 +8,7 @@ local function asLibrary(source) local returns = {} for _, rtn in ipairs(source.returns) do local name = rtn.name - local tp = rtn.type + local tp = rtn.type or 'any' if name then returns[#returns+1] = ('%s: %s'):format(name, tp) else diff --git a/script-beta/utility.lua b/script-beta/utility.lua index c9defebc..9eaeb955 100644 --- a/script-beta/utility.lua +++ b/script-beta/utility.lua @@ -401,15 +401,23 @@ local esc = { function m.viewString(str, quo) if not quo then - if not str:find("'", 1, true) and str:find('"', 1, true) then + if str:find('[\r\n]') then + quo = '[[' + elseif not str:find("'", 1, true) and str:find('"', 1, true) then quo = "'" else quo = '"' end end if quo == "'" then + str = str:gsub('[\000-\008\011-\012\014-\031\127]', function (char) + return ('\\%03d'):format(char:byte()) + end) return quo .. str:gsub([=[['\r\n]]=], esc) .. quo elseif quo == '"' then + str = str:gsub('[\000-\008\011-\012\014-\031\127]', function (char) + return ('\\%03d'):format(char:byte()) + end) return quo .. str:gsub([=[["\r\n]]=], esc) .. quo else if str:find '\r' then @@ -418,12 +426,14 @@ function m.viewString(str, quo) local eqnum = #quo - 2 local fsymb = ']' .. ('='):rep(eqnum) .. ']' if not str:find(fsymb, 1, true) then + str = str:gsub('[\000-\008\011-\012\014-\031\127]', '') return quo .. str .. fsymb end for i = 0, 10 do local fsymb = ']' .. ('='):rep(i) .. ']' if not str:find(fsymb, 1, true) then local ssymb = '[' .. ('='):rep(i) .. '[' + str = str:gsub('[\000-\008\011-\012\014-\031\127]', '') return ssymb .. str .. fsymb end end -- cgit v1.2.3