文件保存或json编解码失败时会有代码位置指示消息

This commit is contained in:
MrZ626
2021-06-19 14:24:21 +08:00
parent 3b675ad8ed
commit b0c71e0f6c
3 changed files with 19 additions and 6 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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