几个table相关函数独立成TABLE模块
This commit is contained in:
@@ -15,7 +15,7 @@ DUMPTABLE=require"Zframework/dumpTable"
|
|||||||
URLENCODE=require"Zframework/urlEncode"
|
URLENCODE=require"Zframework/urlEncode"
|
||||||
|
|
||||||
-- UPPERCHAR=require"Zframework/upperChar"
|
-- UPPERCHAR=require"Zframework/upperChar"
|
||||||
require"Zframework/copyTable"
|
TABLE=require"Zframework/tableExtend"
|
||||||
SPLITSTR=require"Zframework/splitStr"
|
SPLITSTR=require"Zframework/splitStr"
|
||||||
TIMESTR=require"Zframework/timeStr"
|
TIMESTR=require"Zframework/timeStr"
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +1,45 @@
|
|||||||
function copyList(org)
|
local type=type
|
||||||
|
local TABLE={}
|
||||||
|
function TABLE.shift(org)
|
||||||
local L={}
|
local L={}
|
||||||
for i=1,#org do
|
for i=1,#org do
|
||||||
if type(org[i])~="table"then
|
if type(org[i])~="table"then
|
||||||
L[i]=org[i]
|
L[i]=org[i]
|
||||||
else
|
else
|
||||||
L[i]=copyList(org[i])
|
L[i]=TABLE.shift(org[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return L
|
return L
|
||||||
end
|
end
|
||||||
function copyTable(org)
|
function TABLE.copy(org)
|
||||||
local L={}
|
local L={}
|
||||||
for k,v in next,org do
|
for k,v in next,org do
|
||||||
if type(v)~="table"then
|
if type(v)~="table"then
|
||||||
L[k]=v
|
L[k]=v
|
||||||
else
|
else
|
||||||
L[k]=copyTable(v)
|
L[k]=TABLE.copy(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return L
|
return L
|
||||||
end
|
end
|
||||||
function addToTable(G,base)--For all things in G if same type in base, push to base
|
function TABLE.add(G,base)--For all things in G if same type in base, push to base
|
||||||
for k,v in next,G do
|
for k,v in next,G do
|
||||||
if type(v)==type(base[k])then
|
if type(v)==type(base[k])then
|
||||||
if type(v)=="table"then
|
if type(v)=="table"then
|
||||||
addToTable(v,base[k])
|
TABLE.add(v,base[k])
|
||||||
else
|
else
|
||||||
base[k]=v
|
base[k]=v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function completeTable(G,base)--For all things in G if no val in base, push to base
|
function TABLE.complete(G,base)--For all things in G if no val in base, push to base
|
||||||
for k,v in next,G do
|
for k,v in next,G do
|
||||||
if base[k]==nil then
|
if base[k]==nil then
|
||||||
base[k]=v
|
base[k]=v
|
||||||
elseif type(v)=="table"and type(base[k])=="table"then
|
elseif type(v)=="table"and type(base[k])=="table"then
|
||||||
completeTable(v,base[k])
|
TABLE.complete(v,base[k])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return TABLE
|
||||||
@@ -4,8 +4,8 @@ local path="/tech/socket/v1"
|
|||||||
|
|
||||||
local wsThread=[[
|
local wsThread=[[
|
||||||
-- lua + love2d threading websocket client
|
-- lua + love2d threading websocket client
|
||||||
-- original pure lua ver. by flaribbit and Particle_G and MrZ_26
|
-- Original pure lua ver. by flaribbit and Particle_G and MrZ
|
||||||
-- threading version by MrZ_26
|
-- Threading version by MrZ
|
||||||
|
|
||||||
local triggerCHN,sendCHN,readCHN=...
|
local triggerCHN,sendCHN,readCHN=...
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ end
|
|||||||
|
|
||||||
function newBoard(f)--Generate a new board
|
function newBoard(f)--Generate a new board
|
||||||
if f then
|
if f then
|
||||||
return copyList(f)
|
return TABLE.shift(f)
|
||||||
else
|
else
|
||||||
local F={}
|
local F={}
|
||||||
for i=1,20 do F[i]={0,0,0,0,0,0,0,0,0,0}end
|
for i=1,20 do F[i]={0,0,0,0,0,0,0,0,0,0}end
|
||||||
@@ -710,7 +710,7 @@ do--function resetGameData(args)
|
|||||||
local S={}
|
local S={}
|
||||||
for _,key in next,gameSetting do
|
for _,key in next,gameSetting do
|
||||||
if type(SETTING[key])=="table"then
|
if type(SETTING[key])=="table"then
|
||||||
S[key]=copyList(SETTING[key])
|
S[key]=TABLE.shift(SETTING[key])
|
||||||
else
|
else
|
||||||
S[key]=SETTING[key]
|
S[key]=SETTING[key]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -309,7 +309,9 @@ SETTING={--Settings
|
|||||||
VKCurW=.4,--Cur-Pos Weight
|
VKCurW=.4,--Cur-Pos Weight
|
||||||
VKIcon=true,--If disp icon
|
VKIcon=true,--If disp icon
|
||||||
VKAlpha=.3,
|
VKAlpha=.3,
|
||||||
}local S=FILE.load("conf/settings")if S then addToTable(S,SETTING)end
|
}
|
||||||
|
local S=FILE.load("conf/settings")
|
||||||
|
if S then TABLE.add(S,SETTING)end
|
||||||
S=FILE.load("conf/data")
|
S=FILE.load("conf/data")
|
||||||
if S then--Statistics
|
if S then--Statistics
|
||||||
STAT=S
|
STAT=S
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ local function loadGameEnv(P)--Load gameEnv
|
|||||||
if type(v)~="table"then--Default setting
|
if type(v)~="table"then--Default setting
|
||||||
ENV[k]=v
|
ENV[k]=v
|
||||||
else
|
else
|
||||||
ENV[k]=copyTable(v)
|
ENV[k]=TABLE.copy(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not ENV.noMod then
|
if not ENV.noMod then
|
||||||
@@ -244,7 +244,7 @@ local function loadRemoteEnv(P,confStr)--Load gameEnv
|
|||||||
if type(v)~="table"then--Default setting
|
if type(v)~="table"then--Default setting
|
||||||
ENV[k]=v
|
ENV[k]=v
|
||||||
else
|
else
|
||||||
ENV[k]=copyTable(v)
|
ENV[k]=TABLE.copy(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ scene.widgetList={
|
|||||||
WIDGET.newButton{name="importUnlock", x=190,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
WIDGET.newButton{name="importUnlock", x=190,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
||||||
local D=parseCB()
|
local D=parseCB()
|
||||||
if D then
|
if D then
|
||||||
addToTable(D,RANKS)
|
TABLE.add(D,RANKS)
|
||||||
FILE.save(RANKS,"conf/unlock")
|
FILE.save(RANKS,"conf/unlock")
|
||||||
else
|
else
|
||||||
LOG.print(text.importSuccess,COLOR.green)
|
LOG.print(text.importSuccess,COLOR.green)
|
||||||
@@ -58,7 +58,7 @@ scene.widgetList={
|
|||||||
WIDGET.newButton{name="importData", x=490,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
WIDGET.newButton{name="importData", x=490,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
||||||
local D=parseCB()
|
local D=parseCB()
|
||||||
if D then
|
if D then
|
||||||
addToTable(D,STAT)
|
TABLE.add(D,STAT)
|
||||||
FILE.save(STAT,"conf/data")
|
FILE.save(STAT,"conf/data")
|
||||||
else
|
else
|
||||||
LOG.print(text.importSuccess,COLOR.green)
|
LOG.print(text.importSuccess,COLOR.green)
|
||||||
@@ -67,7 +67,7 @@ scene.widgetList={
|
|||||||
WIDGET.newButton{name="importSetting", x=790,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
WIDGET.newButton{name="importSetting", x=790,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
||||||
local D=parseCB()
|
local D=parseCB()
|
||||||
if D then
|
if D then
|
||||||
addToTable(D,SETTING)
|
TABLE.add(D,SETTING)
|
||||||
FILE.save(SETTING,"conf/settings")
|
FILE.save(SETTING,"conf/settings")
|
||||||
else
|
else
|
||||||
LOG.print(text.importSuccess,COLOR.green)
|
LOG.print(text.importSuccess,COLOR.green)
|
||||||
@@ -76,7 +76,7 @@ scene.widgetList={
|
|||||||
WIDGET.newButton{name="importVK", x=1090,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
WIDGET.newButton{name="importVK", x=1090,y=300,w=280,h=100,color="lBlue",font=25,code=function()
|
||||||
local D=parseCB()
|
local D=parseCB()
|
||||||
if D then
|
if D then
|
||||||
addToTable(D,VK_org)
|
TABLE.add(D,VK_org)
|
||||||
FILE.save(VK_org,"conf/virtualkey")
|
FILE.save(VK_org,"conf/virtualkey")
|
||||||
else
|
else
|
||||||
LOG.print(text.importSuccess,COLOR.green)
|
LOG.print(text.importSuccess,COLOR.green)
|
||||||
|
|||||||
Reference in New Issue
Block a user