diff options
author | Edwin Mons <edwin.mons@isode.com> | 2014-05-09 11:45:03 (GMT) |
---|---|---|
committer | Edwin Mons <edwin.mons@isode.com> | 2014-05-12 13:06:20 (GMT) |
commit | 15ccd713a988b8386d06ca9ea10910ae9f59ea5a (patch) | |
tree | 96ba6382a9f26c908efb56e8e58431a1090495c5 /Sluift | |
parent | 634555e64572531fece2a955d1168a88c7979d09 (diff) | |
download | swift-15ccd713a988b8386d06ca9ea10910ae9f59ea5a.zip swift-15ccd713a988b8386d06ca9ea10910ae9f59ea5a.tar.bz2 |
Add sluift function create_form
The function send_mam_query needs an optional form. Created a generic
form creation function, and made the pubsub configuration form function
use that.
Change-Id: I9e839b28df3916c1fd0b09d84a03cc521d1736ad
Diffstat (limited to 'Sluift')
-rw-r--r-- | Sluift/core.lua | 33 | ||||
-rw-r--r-- | Sluift/sluift.cpp | 2 |
2 files changed, 25 insertions, 10 deletions
diff --git a/Sluift/core.lua b/Sluift/core.lua index 48b8a97..ecd3c5e 100644 --- a/Sluift/core.lua +++ b/Sluift/core.lua @@ -442,6 +442,27 @@ local function read_file(file) 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 options = parse_options({}, ...) + local result = { fields = {} } + for var, value in pairs(fields) do + result.fields[#result.fields+1] = { name = var, value = value } + 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 + end + return result +end + -------------------------------------------------------------------------------- -- Metatables -------------------------------------------------------------------------------- @@ -809,14 +830,7 @@ end -------------------------------------------------------------------------------- local function pubsub_node_configuration_to_form(configuration) - if not configuration then - return - end - local fields = { {name = 'form_type', value = 'http://jabber.org/protocol/pubsub#node_config'} } - for var, value in pairs(configuration) do - fields[#fields+1] = { name = var, value = value } - end - return { type = "submit", fields = fields } + return create_form{configuration, form_type="http://jabber.org/protocol/pubsub#node_config", type="submit"} end function PubSubNode:list_items (options) @@ -1018,5 +1032,6 @@ return { help = help, extra_help = extra_help, copy = copy, - with = with + with = with, + create_form = create_form } diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp index a04ceeb..b55649b 100644 --- a/Sluift/sluift.cpp +++ b/Sluift/sluift.cpp @@ -391,7 +391,7 @@ SLUIFT_API int luaopen_sluift(lua_State* L) { // Register convenience functions lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex); std::vector<std::string> coreLibExports = boost::assign::list_of - ("tprint")("disco")("help")("get_help")("copy")("with")("read_file"); + ("tprint")("disco")("help")("get_help")("copy")("with")("read_file")("create_form"); foreach (const std::string& coreLibExport, coreLibExports) { lua_getfield(L, -1, coreLibExport.c_str()); lua_setfield(L, -3, coreLibExport.c_str()); |