Advertisement
Imgoodisher

CC reliable textutils.unserialize

Aug 15th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. --{[1]="hello",[2]=32}
  2.  
  3. function textutils.unserialize(s)
  4.  length = string.len(s)
  5.  t = {}
  6.  for match in string.gmatch(s, "%b{}") do
  7.   if match then
  8.    --print(match)
  9.    for match2 in string.gmatch(s, "%b[]=[^%,]+") do
  10.     if match2 then
  11.      --print(match2)
  12.      _index = string.match(match2, "%b[]")
  13.      if _index then
  14.       index = string.match(_index, "[^%[%]]+")
  15.       if index then
  16.        if tonumber(index) then index = tonumber(index) else
  17.        index = string.gsub(index, '"', "") end
  18.       end
  19.      end
  20.      value = string.sub(string.match(match2, "=.+"), 2)
  21.      --print("("..type(index)..") "..tostring(index)..": "..tostring(value))  
  22.      if value and index then
  23.       t[index] = value
  24.      end
  25.     end
  26.    end
  27.   end
  28.  end
  29.  return t
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement