整理代码,新增string扩展模块,把一些小模块合并进string和table扩展模块中

This commit is contained in:
MrZ626
2021-04-22 11:13:37 +08:00
parent 7b0717c392
commit 402f777a90
91 changed files with 258 additions and 191 deletions

View File

@@ -73,4 +73,60 @@ function TABLE.reIndex(org)
end
end
end
--Dump a simple lua table
do--function TABLE.dump(L,t)
local find=string.find
local tabs={
[0]="",
"\t",
"\t\t",
"\t\t\t",
"\t\t\t\t",
"\t\t\t\t\t",
}
function dump(L,t)
local s
if t then
s="{\n"
else
s="return{\n"
t=1
if type(L)~="table"then
return
end
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 error("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=dump(v,t+1)
elseif T=="boolean"then v=tostring(v)
else error("Error data type!")
end
s=s..tabs[t]..k..v..",\n"
end
return s..tabs[t-1].."}"
end
TABLE.dump=dump
end
return TABLE