summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2014-05-12 14:41:33 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2014-05-12 14:41:33 (GMT)
commita2bd9984a31e426e2ba263e68e6dc0733970026c (patch)
treeb76f16bb0b20771fd40ad36d8144713a335b5d9f
parente5fc9da99eae0d54b4ff5607016fbacfdbf55485 (diff)
downloadswift-contrib-a2bd9984a31e426e2ba263e68e6dc0733970026c.zip
swift-contrib-a2bd9984a31e426e2ba263e68e6dc0733970026c.tar.bz2
Fix create_form to work properly with fields
Change-Id: I02f2ec421bd7ba54f64eff35dc1c6e21a7c22545
-rw-r--r--Sluift/core.lua19
1 files changed, 12 insertions, 7 deletions
diff --git a/Sluift/core.lua b/Sluift/core.lua
index ecd3c5e..616d96c 100644
--- a/Sluift/core.lua
+++ b/Sluift/core.lua
@@ -416,82 +416,87 @@ local function register_get_by_type_index(table)
metatable = {}
setmetatable(table, metatable)
end
metatable.__index = get_by_type
end
return table
end
local function call(options)
local f = options[1]
local result = { xpcall(f, debug.traceback) }
if options.finally then
options.finally()
end
if result[1] then
table.remove(result, 1)
return unpack(result)
else
error(result[2])
end
end
local function read_file(file)
local f = io.open(file, 'rb')
local result = f:read('*all')
f:close()
return result
end
_H = {
[[ Generate a form table, suitable for PubSubConfiguration and MAMQuery ]],
parameters = { {"fields", "The fields that will be converted into a form table"},
{"form_type", "If specified, add a form_type field with this value"},
{"type", "Form type, e.g. 'submit'"} }
}
-local function create_form(fields, ...)
+local function create_form(...)
local options = parse_options({}, ...)
local result = { fields = {} }
- for var, value in pairs(fields) do
- result.fields[#result.fields+1] = { name = var, value = value }
+ -- FIXME: make nicer when parse_options binds positional arguments to names
+ if options.fields then
+ for var, value in pairs(options.fields) do
+ result.fields[#result.fields+1] = { name = var, value = value }
+ end
+ elseif options[1] then
+ for var, value in pairs(options[1]) do
+ result.fields[#result.fields+1] = { name = var, value = value }
+ end
end
if options.form_type then
- result.fields[#result.fields+1] = { name = 'form_type', value = form_type }
- end
- if options.type then
- result['type'] = type
+ result.fields[#result.fields+1] = { name = 'FORM_TYPE', value = options.form_type }
end
+ result['type'] = options.type
return result
end
--------------------------------------------------------------------------------
-- Metatables
--------------------------------------------------------------------------------
_H = {
[[ Client interface ]]
}
local Client = {
_with_prompt = function(client) return client:jid() end
}
Client.__index = Client
register_class_table_help(Client, "Client")
_H = {
[[ Interface to communicate with a PubSub service ]]
}
local PubSub = {}
PubSub.__index = PubSub
register_class_table_help(PubSub, "PubSub")
_H = {
[[ Interface to communicate with a PubSub node on a service ]]
}
local PubSubNode = {}
PubSubNode.__index = PubSubNode
register_class_table_help(PubSubNode, "PubSubNode")
--------------------------------------------------------------------------------
-- with
--------------------------------------------------------------------------------