diff --git a/Zframework/file.lua b/Zframework/file.lua index 71dacc8d..1356fa6f 100644 --- a/Zframework/file.lua +++ b/Zframework/file.lua @@ -4,64 +4,6 @@ local sub,find=string.sub,string.find local toN,toS=tonumber,tostring local concat=table.concat -local tabs={ - [0]="", - "\t", - "\t\t", - "\t\t\t", - "\t\t\t\t", - "\t\t\t\t\t", -} -local function dumpTable(L,t) - local s - if t then - s="{\n" - else - s="return{\n" - t=1 - end - local count=1 - for k,v in next,L do - local T=type(k) - if T=="number"then - if k==count then - k="" - count=count+1 - else - k="["..k.."]=" - end - elseif T=="string"then - if find(k,"[^0-9a-zA-Z_]")then - k="[\""..k.."\"]=" - else - k=k.."=" - end - elseif T=="boolean"then k="["..k.."]=" - else assert(false,"Error key type!") - end - T=type(v) - if T=="number"then v=tostring(v) - elseif T=="string"then v="\""..v.."\"" - elseif T=="table"then v=dumpTable(v,t+1) - elseif T=="boolean"then v=tostring(v) - else assert(false,"Error data type!") - end - s=s..tabs[t]..k..v..",\n" - end - return s..tabs[t-1].."}" -end -local function addToTable(G,base)--Refresh default base with G-values - for k,v in next,G do - if type(v)==type(base[k])then - if type(v)=="table"then - addToTable(v,base[k]) - else - base[k]=v - end - end - end -end - local files={ data= fs.newFile("data.dat"), setting=fs.newFile("settings.dat"), diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index 9aa6ba6c..cceeb8f5 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -39,6 +39,65 @@ do--setFont end end end +do--dumpTable + local tabs={ + [0]="", + "\t", + "\t\t", + "\t\t\t", + "\t\t\t\t", + "\t\t\t\t\t", + } + function dumpTable(L,t) + local s + if t then + s="{\n" + else + s="return{\n" + t=1 + end + local count=1 + for k,v in next,L do + local T=type(k) + if T=="number"then + if k==count then + k="" + count=count+1 + else + k="["..k.."]=" + end + elseif T=="string"then + if find(k,"[^0-9a-zA-Z_]")then + k="[\""..k.."\"]=" + else + k=k.."=" + end + elseif T=="boolean"then k="["..k.."]=" + else assert(false,"Error key type!") + end + T=type(v) + if T=="number"then v=tostring(v) + elseif T=="string"then v="\""..v.."\"" + elseif T=="table"then v=dumpTable(v,t+1) + elseif T=="boolean"then v=tostring(v) + else assert(false,"Error data type!") + end + s=s..tabs[t]..k..v..",\n" + end + return s..tabs[t-1].."}" + end +end +function addToTable(G,base)--Refresh default base with G-values + for k,v in next,G do + if type(v)==type(base[k])then + if type(v)=="table"then + addToTable(v,base[k]) + else + base[k]=v + end + end + end +end function splitStr(s,sep) local L={} local p1,p2=1--start,target