string/table扩展模块新增几个方法用于数据打包/解包

This commit is contained in:
MrZ626
2021-06-06 17:29:57 +08:00
parent f9ed93641c
commit 628365cb49
4 changed files with 89 additions and 30 deletions

View File

@@ -93,7 +93,7 @@ function DATA.copyBoard(page)--Copy the [page] board
end
str=str..S
end
return data.encode('string','base64',data.compress('string','zlib',str))
return STRING.packBin(str)
end
function DATA.copyBoards()
local out={}
@@ -108,12 +108,8 @@ function DATA.pasteBoard(str,page)--Paste [str] data to [page] board
local F=FIELD[page]
--Decode
local res
str=STRING.trim(str)
res,str=pcall(data.decode,'string','base64',str)
if not res then return end
res,str=pcall(data.decompress,'string','zlib',str)
if not res then return end
str=STRING.unpackBin(str)
if not str then return end
local fX,fY=1,1--*ptr for Field(r*10+(c-1))
local p=1

View File

@@ -1,15 +1,7 @@
local scene={}
local function dumpCB(T)
love.system.setClipboardText(
love.data.encode(
'string','base64',
love.data.compress(
'string','zlib',
TABLE.dump(T)
)
)
)
love.system.setClipboardText(STRING.packText(TABLE.dump(T)))
LOG.print(text.exportSuccess,'message')
end
local function parseCB()
@@ -17,10 +9,8 @@ local function parseCB()
local s=love.system.getClipboardText()
--Decode
_,s=pcall(love.data.decode,'string','base64',s)
if not _ then LOG.print(text.dataCorrupted,'error')return end
_,s=pcall(love.data.decompress,'string','zlib',s)
if not _ then LOG.print(text.dataCorrupted,'error')return end
s=STRING.unpackText(s)
if not s then LOG.print(text.dataCorrupted,'error')return end
s=loadstring(s)
if s then