]> git.lizzy.rs Git - dragonblocks3d-lua.git/blobdiff - src/serializer.lua
Refactoring
[dragonblocks3d-lua.git] / src / serializer.lua
diff --git a/src/serializer.lua b/src/serializer.lua
deleted file mode 100644 (file)
index 582e927..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-local serializer = {}
-
-function serializer:serialize()
-       local data = "{"
-       for k, v in pairs(self) do
-               local kdata, vdata
-               local ktype, vtype = type(k), type(v)
-               local serialize_pair = true
-               if ktype == "number" then
-                       kdata = "[" .. k .. "]"
-               elseif ktype == "string" then
-                       if k:sub(1, 1) == "_" then
-                               serialize_pair = false
-                       else
-                               kdata = "[\"" .. k .. "\"]"
-                       end
-               else
-                       serialize_pair = false
-               end
-               if vtype == "table" then
-                       vdata = serializer.serialize(v)
-               elseif vtype == "string" then
-                       vdata = "\"" .. v .. "\""
-               elseif vtype == "number" then
-                       vdata = v
-               elseif vtype == "boolean" then
-                       vdata = v and "true" or "false"
-               else
-                       serialize_pair = false
-               end
-               if serialize_pair then
-                       data = data .. kdata .. "=" .. vdata .. ","
-               end
-       end
-       return data .. "}"
-end
-
-function serializer:deserialize(raw)
-       raw = "return" .. (raw or "")
-       local f = loadstring(raw)
-       local data = f and f()
-       if type(data) == "table" then
-               for k, v in pairs(data) do
-                       self[k] = v
-               end
-       end
-end
-
-return serializer