net.*: Remove use of module() function
[prosody.git] / util / dataforms.lua
index 01a8eef327c1ac566a0ecfabb997c03207f6f237..244fb3f31b3aff563c156012212058e53a4a1b59 100644 (file)
@@ -1,26 +1,26 @@
 -- Prosody IM
 -- Copyright (C) 2008-2010 Matthew Wild
 -- Copyright (C) 2008-2010 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
 
 local setmetatable = setmetatable;
-local pairs, ipairs = pairs, ipairs;
+local ipairs = ipairs;
 local tostring, type, next = tostring, type, next;
 local t_concat = table.concat;
 local st = require "util.stanza";
 local jid_prep = require "util.jid".prep;
 
-module "dataforms"
+local _ENV = nil;
 
 local xmlns_forms = 'jabber:x:data';
 
 local form_t = {};
 local form_mt = { __index = form_t };
 
-function new(layout)
+local function new(layout)
        return setmetatable(layout, form_mt);
 end
 
@@ -32,13 +32,13 @@ function form_t.form(layout, data, formtype)
        if layout.instructions then
                form:tag("instructions"):text(layout.instructions):up();
        end
-       for n, field in ipairs(layout) do
+       for _, field in ipairs(layout) do
                local field_type = field.type or "text-single";
                -- Add field tag
                form:tag("field", { type = field_type, var = field.name, label = field.label });
 
                local value = (data and data[field.name]) or field.value;
-               
+
                if value then
                        -- Add value, depending on type
                        if field_type == "hidden" then
@@ -102,11 +102,11 @@ function form_t.form(layout, data, formtype)
                        end
                        form:up();
                end
-               
+
                if field.required then
                        form:tag("required"):up();
                end
-               
+
                -- Jump back up to list of fields
                form:up();
        end
@@ -121,7 +121,7 @@ function form_t.data(layout, stanza)
 
        for _, field in ipairs(layout) do
                local tag;
-               for field_tag in stanza:childtags() do
+               for field_tag in stanza:childtags("field") do
                        if field.name == field_tag.attr.var then
                                tag = field_tag;
                                break;
@@ -238,7 +238,9 @@ field_readers["hidden"] =
                return field_tag:get_child_text("value");
        end
 
-return _M;
+return {
+       new = new;
+};
 
 
 --[=[