Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: Bolodefchoco
- --Made in: 24/03/2016
- --Last update: 01/04/2017
- --[[ Notes:
- Does:
- Caso x seja uma tabela
- Faz com que a tabela vire uma string
- Caso x seja uma string
- Faz com que a string vire uma tabela
- Args:
- x --> Informação a ser transformada
- ]]--
- serialization = function(x)
- if type(x) == "table" then
- local str = {}
- for index,value in next,x do
- local v = type(value)
- local prefix = (v == "string" and "@" or v == "boolean" and "!" or v == "number" and "#" or v == "table" and "%" or "")
- if prefix then
- local data
- if prefix == "@" then
- data = table.concat({string.byte(value,1,#value)},".")
- elseif prefix == "!" then
- data = (value and 1 or 0)
- elseif prefix == "#" then
- data = tostring(value)
- elseif prefix == "%" then
- data = string.format("{%s}",serialization(value):gsub(";","?"))
- end
- str[#str + 1] = string.format(":%s%s%s;",index,prefix,data)
- end
- end
- return table.concat(str)
- elseif type(x) == "string" then
- local list = {}
- for str in x:gmatch("(.-);") do
- local index,vtype,value = str:match(":(.-)(%p)(.+)")
- if index and vtype and value then
- index = tonumber(index) or index
- if vtype == "@" then
- local sub = {}
- for i in value:gmatch("[^%.]+") do
- sub[#sub+1] = i
- end
- list[index] = string.char(table.unpack(sub))
- elseif vtype == "!" then
- list[index] = (value == "1")
- elseif vtype == "#" then
- list[index] = tonumber(value)
- elseif vtype == "%" then
- list[index] = serialization(value:gsub("{",""):gsub("}",""):gsub("%?",";"))
- end
- end
- end
- return list
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement