From 65faa84351b07dea77aa4052ba5f71ef76e72af5 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Tue, 6 Apr 2021 15:20:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86table=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/tableExtend.lua | 25 ++++++++++++++++--------- parts/globalTables.lua | 2 +- parts/scenes/savedata.lua | 8 ++++---- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Zframework/tableExtend.lua b/Zframework/tableExtend.lua index b3f9537e..fea18fea 100644 --- a/Zframework/tableExtend.lua +++ b/Zframework/tableExtend.lua @@ -28,11 +28,11 @@ function TABLE.copy(org) end --For all things in G if same type in base, push to base -function TABLE.add(G,base) +function TABLE.update(G,base) for k,v in next,G do if type(v)==type(base[k])then if type(v)=="table"then - TABLE.add(v,base[k]) + TABLE.update(v,base[k]) else base[k]=v end @@ -40,13 +40,6 @@ function TABLE.add(G,base) end end ---Clear the table -function TABLE.clear(G) - for k in next,G do - G[k]=nil - end -end - --For all things in G if no val in base, push to base function TABLE.complete(G,base) for k,v in next,G do @@ -58,6 +51,20 @@ function TABLE.complete(G,base) end end +--Remove positive integer index of table +function TABLE.cut(G) + for i=#G,1,-1 do + G[i]=nil + end +end + +--Clear table +function TABLE.clear(G) + for k in next,G do + G[k]=nil + end +end + --Re-index string value of a table function TABLE.reIndex(org) for k,v in next,org do diff --git a/parts/globalTables.lua b/parts/globalTables.lua index ece00317..501ee680 100644 --- a/parts/globalTables.lua +++ b/parts/globalTables.lua @@ -299,7 +299,7 @@ SETTING={--Settings VKAlpha=.3, } local S=FILE.load("conf/settings") -if S then TABLE.add(S,SETTING)end +if S then TABLE.update(S,SETTING)end S=FILE.load("conf/data") if S then--Statistics STAT=S diff --git a/parts/scenes/savedata.lua b/parts/scenes/savedata.lua index e5b8eacb..8050e8aa 100644 --- a/parts/scenes/savedata.lua +++ b/parts/scenes/savedata.lua @@ -49,7 +49,7 @@ scene.widgetList={ WIDGET.newButton{name="importUnlock", x=190,y=300,w=280,h=100,color="lBlue",font=25,code=function() local D=parseCB() if D then - TABLE.add(D,RANKS) + TABLE.update(D,RANKS) FILE.save(RANKS,"conf/unlock") LOG.print(text.importSuccess,"message") else @@ -59,7 +59,7 @@ scene.widgetList={ WIDGET.newButton{name="importData", x=490,y=300,w=280,h=100,color="lBlue",font=25,code=function() local D=parseCB() if D and D.version==STAT.version then - TABLE.add(D,STAT) + TABLE.update(D,STAT) FILE.save(STAT,"conf/data") LOG.print(text.importSuccess,"message") else @@ -69,7 +69,7 @@ scene.widgetList={ WIDGET.newButton{name="importSetting", x=790,y=300,w=280,h=100,color="lBlue",font=25,code=function() local D=parseCB() if D then - TABLE.add(D,SETTING) + TABLE.update(D,SETTING) FILE.save(SETTING,"conf/settings") LOG.print(text.importSuccess,"message") else @@ -79,7 +79,7 @@ scene.widgetList={ WIDGET.newButton{name="importVK", x=1090,y=300,w=280,h=100,color="lBlue",font=25,code=function() local D=parseCB() if D then - TABLE.add(D,VK_org) + TABLE.update(D,VK_org) FILE.save(VK_org,"conf/virtualkey") LOG.print(text.importSuccess,"message") else