1 개요[ | ]
- Lua serialize()
- Lua table_to_string()
lua
Copy
function serialize(arr)
local s = ""
for i,v in pairs(arr) do
if type(v) == "table" then s=s..i..":"..serialize(v)..","
else s=s..v.."," end
end
return "{"..s.."}"
end
t = {}
t["numbers"]={11,12,13}
t["numbers2"]={21,22,23}
t["object2"]={3.14, 777, 'Hello', -0.511, 'World'}
print(serialize(t))
Loading
lua
Copy
function serialize(tbl)
local s = '{'
for k, v in pairs(tbl) do
if type(k) == 'string' then s = s..k..':' end
if type(v) == 'table' then s = s..serialize(v)..','
elseif type(v) == 'string' then s = s..'"'..v..'"'..','
else s = s..tostring(v)..',' end
end
if s ~= '' then s = s:sub(1, s:len()-1) end
return s..'}'
end
t = {}
t["i"]=42
t["b"]=false
t["s"]="hello"
t["numbers"]={11,12,true}
t["numbers2"]={21,22,23}
t["object2"]={3.14, 777, 'Hello', -0.511, 'World'}
print(serialize(t))
Loading
2 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.