易网时代-编程资源站
Welcome
微信登录
编程资源
图片资源库
蚂蚁家优选
PDF转换器
软件资源
软件开发
、
小程序制作
、
系统集成与运维
、
空间租用
、
硬件开发
、
视频监控
、
技术咨询与支持
——联系电话:0311-88999002/88999003
首页
/
操作系统
/
Linux
/
Lua Table的序列化与反序列化函数
Lua Table的序列化与反序列化函数
table.tostring = function(t)
local mark={}
local assign={}
local function ser_table(tbl,parent)
mark[tbl]=parent
local tmp={}
for
k,v
in
pairs(tbl) do
local key= type(k)==
"number"
and
"["
..k..
"]"
or
"["
.. string.format(
"%q"
, k) ..
"]"
if
type(v)==
"table"
then
local dotkey= parent.. key
if
mark[v] then
table.insert(assign,dotkey..
"=""
..mark[v] ..
"""
)
else
table.insert(tmp, key..
"="
..ser_table(v,dotkey))
end
elseif type(v) ==
"string"
then
table.insert(tmp, key..
"="
.. string.format(
"%q"
, v))
elseif type(v) ==
"number"
or
type(v) ==
"boolean"
then
table.insert(tmp, key..
"="
.. tostring(v))
end
end
return
"{"
..table.concat(tmp,
","
)..
"}"
end
return
"do local ret="
..ser_table(t,
"ret"
)..table.concat(assign,
" "
)..
" return ret end"
end
table.loadstring = function(strData)
local f = loadstring(strData)
if
f then
return
f()
end
end
更多关于Lua的详细信息,或者下载地址请点这里
收藏该网址
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图