From b0c71e0f6c5a38b7f47c6066c58f057e60644b56 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sat, 19 Jun 2021 14:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BF=9D=E5=AD=98=E6=88=96js?= =?UTF-8?q?on=E7=BC=96=E8=A7=A3=E7=A0=81=E5=A4=B1=E8=B4=A5=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E6=9C=89=E4=BB=A3=E7=A0=81=E4=BD=8D=E7=BD=AE=E6=8C=87?= =?UTF-8?q?=E7=A4=BA=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/file.lua | 2 +- Zframework/json.lua | 8 ++++---- Zframework/message.lua | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Zframework/file.lua b/Zframework/file.lua index 33f4f255..99acdda9 100644 --- a/Zframework/file.lua +++ b/Zframework/file.lua @@ -50,7 +50,7 @@ function FILE.save(data,name,mode) F:flush()F:close() if not success then MES.new('error',text.saveError..(mes or"unknown error")) - MES.new(false,debug.traceback()) + MES.traceback(1) end return success end diff --git a/Zframework/json.lua b/Zframework/json.lua index bfa85f15..ba13ad9f 100644 --- a/Zframework/json.lua +++ b/Zframework/json.lua @@ -118,8 +118,8 @@ function json.encode(val) local a,b=pcall(encode,val) if a then return b - elseif MES.new then - MES.new('error',text.jsonError..": "..(b or"uknErr")) + elseif MES then + MES.traceback(1) end end @@ -348,8 +348,8 @@ function json.decode(str) local a,b=pcall(decode,str) if a then return b - elseif MES.new then - MES.new('error',text.jsonError..": "..(b or"uknErr")) + elseif MES then + MES.traceback(1) end end return json \ No newline at end of file diff --git a/Zframework/message.lua b/Zframework/message.lua index aed24b7c..dee9113a 100644 --- a/Zframework/message.lua +++ b/Zframework/message.lua @@ -63,7 +63,7 @@ function MES.new(icon,str,time) if type(icon)=='string'then icon=mesIcon[icon]end local t=gc.newText(getFont(30),str) local w=math.max(t:getWidth()+(icon and 45 or 5),200)+20 - local h=math.max(t:getHeight(),46) + local h=math.max(t:getHeight(),46)+3 local L={w,h, {'clear',.5,.5,.5,.7}, {'setCL',.7,.7,.7}, @@ -114,4 +114,17 @@ function MES.draw() end gc_pop() end + +function MES.traceback(n) + local mes= + debug.traceback("",(n or 1)+1) + :gsub(": in function",", in") + :gsub(":"," ") + :gsub("\t","") + MES.new('error',mes:sub( + mes:find("\n",2)+1, + mes:find("\n%[C%], in 'xpcall'") + ),5) +end + return MES \ No newline at end of file