examples/xep0004.lua
changeset 8 fc9060b9b7cc
parent 7 eb6d89bf1fbf
child 20 fd96da2c3acc
--- a/examples/xep0004.lua	Tue Feb 24 19:42:48 2009 +0200
+++ b/examples/xep0004.lua	Wed Feb 25 22:58:34 2009 +0200
@@ -1,5 +1,12 @@
 
 forms = { }
+form_cid = 0
+
+function insert_form ( form )
+	table.insert ( forms, form )
+	main.add_completion ( form_cid, tostring(#forms) )
+	return #forms
+end
 
 -- expects lm node   x = { xmlns = 'jabber:x:data', type = 'form', ... }
 -- returns form index in forms table, you can do whatever you want to upper level table, except exp and val fields.
@@ -77,8 +84,7 @@
 		end
 		field = field:next ()
 	end
-	table.insert ( forms, form )
-	return #forms
+	return insert_form ( form )
 end
 
 function form_set ( id, name, value )
@@ -99,7 +105,7 @@
 	end
 end
 
-main.command ( 'form',
+form_cid = main.command ( 'form',
 	function ( args )
 		args = parse_args ( args )
 		local action = args[1]
@@ -133,6 +139,7 @@
 			end
 		elseif action == 'del' then
 			forms[tonumber(args[2])] = nil
+			main.del_completion ( form_cid, tostring(args[2]) )
 		elseif action == 'send' then
 			local form = forms[tonumber(args[2])]
 			if form then
@@ -144,7 +151,7 @@
 				print ( ' - ' .. tostring(id) .. ' ' .. form.title .. ' [' .. ( form.status or 'unknown' ) .. ']' )
 			end
 		end
-	end )
+	end, { "del", "send" } )
 
 commands_help['form'] = "[del form_id | send form_id | form_id [field_name {clear | [set] value}]\n\nWith bare form id prints info on that form.\nWith field name sets or clears field value. Set subcommand is optional, just to allow values, starting with 'clear'.\nWithout arguments prints form list."