Changed the ejabberd import script to use util.serialization
authorWaqas Hussain <waqas20@gmail.com>
Thu, 4 Dec 2008 18:40:15 +0000 (23:40 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Thu, 4 Dec 2008 18:40:15 +0000 (23:40 +0500)
tools/ejabberd2prosody.lua
tools/serialize.lua [deleted file]

index 33f60c99bfad0ffeebf8a68972d4e4a3dd318918..e66b85130dc1dfd04985163db441b9baf223f852 100755 (executable)
@@ -21,9 +21,9 @@
 
 \r
 require "erlparse";\r
-require "serialize";\r
 \r
 package.path = package.path ..";../?.lua";\r
+local serialize = require "util.serialization".serialize;
 local st = require "util.stanza";\r
 package.loaded["util.logger"] = {init = function() return function() end; end}\r
 local dm = require "util.datamanager"\r
@@ -74,7 +74,7 @@ function build_stanza(tuple, stanza)
        elseif tuple[1] == "xmlcdata" then\r
                stanza:text(tuple[2]);\r
        else\r
-               error("unknown element type: "..serialize.serialize(tuple));\r
+               error("unknown element type: "..serialize(tuple));\r
        end\r
 end\r
 function build_time(tuple)\r
@@ -190,7 +190,7 @@ for item in erlparse.parseFile(arg) do
        count = count + 1;\r
        local name = item[1];\r
        t[name] = (t[name] or 0) + 1;\r
-       --print(count, serialize.serialize(item));\r
+       --print(count, serialize(item));\r
        if filters[name] then filters[name](item); end\r
 end\r
---print(serialize.serialize(t));\r
+--print(serialize(t));\r
diff --git a/tools/serialize.lua b/tools/serialize.lua
deleted file mode 100644 (file)
index 77c05e1..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
--- Prosody IM v0.1
--- Copyright (C) 2008 Matthew Wild
--- Copyright (C) 2008 Waqas Hussain
--- 
--- This program is free software; you can redistribute it and/or
--- modify it under the terms of the GNU General Public License
--- as published by the Free Software Foundation; either version 2
--- of the License, or (at your option) any later version.
--- 
--- This program is distributed in the hope that it will be useful,
--- but WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--- GNU General Public License for more details.
--- 
--- You should have received a copy of the GNU General Public License
--- along with this program; if not, write to the Free Software
--- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
---
-
-
-\r
-local indent = function(i)\r
-       return string.rep("\t", i);\r
-end\r
-local function basicSerialize (o)\r
-       if type(o) == "number" or type(o) == "boolean" then\r
-               return tostring(o);\r
-       else -- assume it is a string -- FIXME make sure it's a string. throw an error otherwise.\r
-               return (string.format("%q", tostring(o)):gsub("\\\n", "\\n"));\r
-       end\r
-end\r
-local function _simplesave (o, ind, t)\r
-       if type(o) == "number" then\r
-               table.insert(t, tostring(o));\r
-       elseif type(o) == "string" then\r
-               table.insert(t, (string.format("%q", o):gsub("\\\n", "\\n")));\r
-       elseif type(o) == "table" then\r
-               table.insert(t, "{\n");\r
-               for k,v in pairs(o) do\r
-                       table.insert(t, indent(ind));\r
-                       table.insert(t, "[");\r
-                       table.insert(t, basicSerialize(k));\r
-                       table.insert(t, "] = ");\r
-                       _simplesave(v, ind+1, t);\r
-                       table.insert(t, ",\n");\r
-               end\r
-               table.insert(t, indent(ind-1));\r
-               table.insert(t, "}");\r
-       elseif type(o) == "boolean" then\r
-               table.insert(t, (o and "true" or "false"));\r
-       else\r
-               error("cannot serialize a " .. type(o))\r
-       end\r
-end\r
-local t_concat = table.concat;\r
-\r
-module "serialize"\r
-\r
-function serialize(o)\r
-       local t = {};\r
-       _simplesave(o, 1, t);\r
-       return t_concat(t);\r
-end\r
-\r
-return _M;\r