Put help into separate files
authorMyhailo Danylenko <isbear@ukrpost.net>
Sun, 20 May 2012 06:24:53 +0300
changeset 121 75a7d595817c
parent 120 1be9411caf31
child 122 9a803cc75245
Put help into separate files * add lua command help * convert some (useful) examples help to help files * fix evil missing brace * cosmetics
CMakeLists.txt
examples/README
examples/attention.lua
examples/evil.lua
examples/forms.lua
examples/help/en/hlp_attention.txt
examples/help/en/hlp_blocklist.txt
examples/help/en/hlp_cancel.txt
examples/help/en/hlp_form.txt
examples/help/en/hlp_post.txt
examples/help/en/hlp_register.txt
examples/help/en/hlp_remote.txt
examples/help/en/hlp_room-config.txt
examples/help/en/hlp_toggle.txt
examples/help/en/hlp_vcard-temp.txt
examples/mcabberrc.lua
examples/muc.lua
examples/privacy.lua
examples/register.lua
examples/remote.lua
examples/vcard.lua
help/en/hlp_lua.txt
lua.c
--- a/CMakeLists.txt	Sun May 20 06:24:50 2012 +0300
+++ b/CMakeLists.txt	Sun May 20 06:24:53 2012 +0300
@@ -98,6 +98,7 @@
 endif()
 install(DIRECTORY examples DESTINATION share/doc/${CPACK_PACKAGE_NAME} PATTERN "*~" EXCLUDE)
 install(FILES README TODO COPYING DESTINATION share/doc/${CPACK_PACKAGE_NAME})
+install(DIRECTORY help DESTINATION share/mcabber)
 install(FILES ${PROJECT_BINARY_DIR}/lua.avv DESTINATION share/mcabber/avv/modules RENAME lua)
 
 ## The End ## vim: se ts=4: ##
--- a/examples/README	Sun May 20 06:24:50 2012 +0300
+++ b/examples/README	Sun May 20 06:24:53 2012 +0300
@@ -1,5 +1,5 @@
 
-How to use these scrpits (and how they are organized):
+# How to use these scrpits (and how they are organized):
 
 Scripts are generally separated into two classes - library
 (those in lm subdirectory), that deal mainly with lm and xmpp
@@ -7,10 +7,9 @@
 scripts - mcabber commands, mcabber message handlers, etc.
 
 Most of mcabber scripts expect to be require'd from
-mcabberrc.lua, that will provide common hook and help
-infrastructure. For 'require' to find scripts, you need to
+mcabberrc.lua. For 'require' to find scripts, you need to
 properly set package.path, and in mcabberrc.lua there is
-example of this on the beginning. Some of this functionality
+example of this at the beginning. Some of this functionality
 is already implemented in C (and implemented better), so,
 first look at Modules wiki page.
 
@@ -22,43 +21,43 @@
 commands, registration to jabber entities, muc room administration
 and some more.
 
-So, first you need to get development version of mcabber, compiled
-with --modules-enable. Then you need to build this module. For
-that see README in top-level dir.
+So, first you need mcabber with enabled dynamic module loading.
+This shouldn't be a problem, as this is now default. Then you need
+to build this module. For that see README in top-level dir.
 
 Then you need to set modules_dir in your mcabberrc to point to
 directory, where your modules will reside. Now you can issue
-'/load lua' command and get module working. It will provide one
-command - '/lua' (and also some lua functions to allow lua to
-manipulate mcabber to some extent), that evaluates specified
+'/module load lua' command and get module working. It will
+provide one command - '/lua' (and also some lua functions to allow
+lua to manipulate mcabber to some extent), that evaluates specified
 lua expression.
 
 Lua module allows to automatically run specified lua file at
 module loading. The name of this file is determined from variable
-lua_init_filename. To use these scripts it should point to
+lua_init_filename. To use these example scripts it should point to
 your edited version of mcabberrc.lua. Also there are some other
 variables, that need to be set up for proper scripts functioning,
-you can find these values in lua.rc. Note, though, that some
-scripts are now unused by me and generally are considered only
-as example - eg jobs, marking etc. In mcabberrc.lua you should
-edit (if necessary) pacakage.path on beginning and set of
-require'd scripts in the end. Rigth now I am using transports,
-room_priv, forms, privacy, muc, vcard, oob, register, remote and
-attention scripts.
+you can find these values in lua.rc in this dir. Note, though, that
+some scripts are now unused by me and generally are considered only
+as example - eg jobs, marking etc. In mcabberrc.lua you should edit
+(if necessary) pacakage.path on beginning and set of require'd
+scripts in the end. Right now I am using 'transports', 'room_priv',
+'forms', 'privacy', 'muc', 'vcard', 'oob', 'register', 'remote' and
+'attention' scripts.
 
-Amongst these muc, vcard, register and remote depend on forms,
-and thus have no hope to be implemented in C in near future.
+Amongst these, 'muc', 'vcard', 'register' and 'remote' depend on
+'forms', and thus have no hope to be implemented in C in near future.
 
 Ah, and almost forgot to mention - for some of the scripts you
-need some external lua modules. First, it is lua-lm - lua
-interface to loudmouth. It is written by me, and thus can be
-fond at the same place, where you find a lua mcabber module.
-Others are posix, base64, socket, sha1 and md5. First three were
-until recent time in Debian repository. Latter two are built from
+need some external lua modules. First, it is 'lua-lm' - lua
+interface for 'loudmouth'. It is written by me, and thus can be
+found in the same place, where you've got a 'lua' mcabber module.
+Others are 'posix', 'base64', 'socket', 'sha1' and 'md5'. First three
+were until recent time in Debian repository. Latter two are built from
 one source at http://www.inf.puc-rio.br/~roberto/md5/md5-5/md5.html.
-You can find out, which modules require your scripts by looking at
+You can find out, which modules script requires by looking at
 'require' lines at the beginning (do not forget to look at scripts,
-that are require'd by this script).
+that are 'require'd by this script).
 
   -- Myhailo Danylenko <isbear@ukrpost.net>
 
--- a/examples/attention.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/attention.lua	Sun May 20 06:24:53 2012 +0300
@@ -35,8 +35,6 @@
 		attention.send ( lm.connection.bless ( connection ), who, args[1] )
 	end, true, 'jid' )
 
-commands_help['attention'] = "[-t to] [message]\n\nTries to get buddy's attention."
-
 local attention_handler = lm.message_handler.new ( attention.message_handler )
 local attention_handler_registered = false
 
--- a/examples/evil.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/evil.lua	Sun May 20 06:24:53 2012 +0300
@@ -105,7 +105,7 @@
 	function ( args )
 		main.add_feature ( 'http://jabber.org/protocol/evil' )
 		evil_pc_handler ()
-	end
+	end )
 main.hook ( 'hook-lua-quit',
 	function ( args )
 		main.del_feature ( 'http://jabber.org/protocol/evil' )
--- a/examples/forms.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/forms.lua	Sun May 20 06:24:53 2012 +0300
@@ -111,6 +111,4 @@
 		end
 	end, true, form_cid )
 
-commands_help['form'] = "[form_id [send | reject | [set | add] fieldname [value]]]\n\nWithout arguments prints form list.\nWith bare form id prints info on that form.\nWhen setting multivalue field, new values are added, not replacing previous.\nWithout value unsets field, multivalue fields lose all their values.\nAdd command allws to append field to form end.\nNote, that form-specific default type will be used."
-
 -- vim: se ts=4: --
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_attention.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,5 @@
+
+ /attention [-t to] [message]
+
+(lua command)
+Tries to get buddy's attention.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_blocklist.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,6 @@
+
+ /blocklist [[add | del] [jid]]
+
+(lua command)
+Retrieves list, adds or removes buddies in mcabber's server blocklist.
+Any stanzas from a buddy in this list are blocked by the server.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_cancel.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,5 @@
+
+ /cancel [jid]
+
+(lua command)
+Sends registration cancellation request to jid (or current buddy). May require a form filling.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_form.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,10 @@
+
+ /form [form_id [send | reject | [set | add] fieldname [value]]]
+
+(lua command)
+Without arguments prints form list.
+With bare form id prints info on that form.
+When setting multivalue field, new values are added, not replacing previous.
+Without value unsets field, multivalue fields lose all of their values.
+Add command allows to append field to form end.
+Note, that form-specific default type will be used.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_post.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,6 @@
+
+ /post filename
+
+(lua command)
+Sends given file as a message to current buddy.
+In fact, equal to templatecmd 'say_to -f $1 .'.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_register.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,5 @@
+
+ /register [jid]
+
+(lua command)
+Sends registration request to jid (or current buddy). You, probably, will then fill and submit some form.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_remote.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,5 @@
+
+ /remote [-t target_jid] [remote_command]
+
+(lua command)
+Prints list of available remote commands or requests execution of specified command.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_room-config.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,5 @@
+
+ /room-config [room_jid]
+
+(lua command)
+Requests room configuration form from server. You must be the owner of this room.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_toggle.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,5 @@
+
+ /toggle
+
+(lua command)
+Switches between online and away statuses.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/help/en/hlp_vcard-temp.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,7 @@
+
+ /vcard-temp [photo_filename | . | jid]
+
+(lua command)
+Obtains vcard (as a form, but you may not submit it).
+Without requuests your own vcard.
+You can also set your photo from given file - mcabber will request vcard, set new photo and submit it to server.
--- a/examples/mcabberrc.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/mcabberrc.lua	Sun May 20 06:24:53 2012 +0300
@@ -117,7 +117,7 @@
 
 -- COMMANDS
 
--- Help strings should not contain command, only arguments. This is necessary to support soft aliases.
+--[[ Help strings should not contain command, only arguments. This is necessary to support soft aliases.
 commands_help = {
 	post      = "filename\n\nSends file as a message. Just shorthand.",
 	beep      = "[enable|disable|on|off|yes|no|true|false]\n\nEnables or disables beeping on all messages.\nIf state is omitted, prints current state.",
@@ -127,11 +127,13 @@
 	count     = "\n\nPrints number of resources of current buddy. Useful to determine member count of large room.",
 	toggle    = "\n\nToggles away/online status.",
 }
+--]]
 
 main.command ( 'post',
 	function ( args )
 		main.run ( 'say_to -f ' .. args .. ' .' )
 	end, false, 'filename' )
+--[[
 main.command ( 'cmd',
 	function ( args )
 		local to = main.current_buddy ()
@@ -172,6 +174,7 @@
 		end
 		print ( "Resource count: " .. count )
 	end )
+--]]
 main.command ( 'toggle',
 	function ( args )
 		local stat, mess = main.status ()
--- a/examples/muc.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/muc.lua	Sun May 20 06:24:53 2012 +0300
@@ -43,6 +43,4 @@
 			end )
 	end, false, 'jid' )
 
-commands_help['room-config'] = "[room_jid]\n\nRequests room configuration form from server. You must be owner of this room."
-
 -- vim: se ts=4 sw=4: --
--- a/examples/privacy.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/privacy.lua	Sun May 20 06:24:53 2012 +0300
@@ -66,8 +66,6 @@
 			end )
 	end, true )
 
-commands_help['blocklist'] = '[[add | del] [jid]]\n\nRetrieves list, adds or removes buddies to/from mcabber\'s server blocklist.\nAny stanzas from buddy in list are blocked by server.'
-
 local privacy_handler            = lm.message_handler.new ( privacy.iq_handler )
 local privacy_handler_registered = false
 
--- a/examples/register.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/register.lua	Sun May 20 06:24:53 2012 +0300
@@ -85,7 +85,4 @@
 			end )
 	end, false, 'jid' )
 
-commands_help['register'] = "[jid]\n\nSends registration request to jid (or current buddy). You, probably, then will need to fill and send some form."
-commands_help['cancel'] = "[jid]\n\nSends registration cancellation request to jid (or current buddy). May require a form filling."
-
 -- vim: se ts=4 sw=4: --
--- a/examples/remote.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/remote.lua	Sun May 20 06:24:53 2012 +0300
@@ -66,6 +66,4 @@
 		end
 	end, true, 'jid' )
 
-commands_help['remote'] = "[-t target_jid] [remote_command]\n\nPrints list of available remote command or requests execution of specified command."
-
 -- vim: se ts=4 sw=4: --
--- a/examples/vcard.lua	Sun May 20 06:24:50 2012 +0300
+++ b/examples/vcard.lua	Sun May 20 06:24:53 2012 +0300
@@ -96,6 +96,4 @@
 			end )
 	end, true, 'jid' )
 
-commands_help['vcard-temp'] = '[photo filename | . | jid]\n\nObtains vcard (as a form, but you may not submit it). Without arguments obtains your own vcard. "." means current buddy.\nYou can also publish your photo from file, that will automatically get your vcard, put a data into it and submit to server.'
-
 -- vim: se ts=4 sw=4: --
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/help/en/hlp_lua.txt	Sun May 20 06:24:53 2012 +0300
@@ -0,0 +1,4 @@
+
+ /lua string
+
+Evaluate given string as lua code in mcabber environment.
--- a/lua.c	Sun May 20 06:24:50 2012 +0300
+++ b/lua.c	Sun May 20 06:24:53 2012 +0300
@@ -45,25 +45,35 @@
 #include "config.h"
 #include "util.h"
 
-// module description
+//
+//  options
+//
+
+#define OPT_MLUA_RC       "lua_init_filename"
+#define OPT_MLUA_LM_DEBUG "lua_lm_debug"
+
+//
+//  module description
+//
+
 void mlua_init   (void);
 void mlua_uninit (void);
 
 #ifdef LLM_LOG_HANDLER
 #define DESCRIPTION ( \
 	"Lua scripting interface\n" \
-	"Recognizes options lua_init_file, lua_hook_function and lua_lm_debug\n" \
-	"Provides command /lua" )
+	"Options: " OPT_MLUA_RC ", " OPT_MLUA_LM_DEBUG "\n" \
+	"Command: /lua" )
 #else
 #define DESCRIPTION ( \
 	"Lua scripting interface\n" \
-	"Recognizes options lua_init_file and lua_hook_function\n" \
-	"Provides command /lua" )
+	"Options: " OPT_MLUA_RC "\n" \
+	"Command: /lua" )
 #endif
 
-static module_info_t info_lua_experimental = {
-	.branch      = "experimental",
-	.api         = 34,
+static module_info_t info_lua_dev = {
+	.branch      = "dev",
+	.api         = 23,
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
 	.requires    = NULL,
@@ -72,18 +82,7 @@
 	.next        = NULL,
 };
 
-static module_info_t info_lua_dev = {
-	.branch      = "dev",
-	.api         = 20,
-	.version     = PROJECT_VERSION,
-	.description = DESCRIPTION,
-	.requires    = NULL,
-	.init        = mlua_init,
-	.uninit      = mlua_uninit,
-	.next        = &info_lua_experimental,
-};
-
-module_info_t info_lua_0_10_0 = {
+static module_info_t info_lua_0_10_0 = {
 	.branch      = "0.10.0",
 	.api         = 1,
 	.version     = PROJECT_VERSION,
@@ -105,6 +104,10 @@
 	.next        = &info_lua_0_10_0,
 };
 
+//
+//  globals
+//
+
 #ifdef MCABBER_API_HAVE_CMD_ID
 static gpointer lua_cmdid;
 #endif
@@ -112,6 +115,10 @@
 // global lua state object, necessary for uninitialization function
 static lua_State *lua = NULL;
 
+//
+//  code
+//
+
 // caller sould g_free result
 static char *mcabber_config_filename (const char *file)
 {
@@ -1605,7 +1612,7 @@
 
 void lua_lm_log_handler (const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer ignore)
 {
-	if (settings_opt_get_int ("lua_lm_debug"))
+	if (settings_opt_get_int (OPT_MLUA_LM_DEBUG))
 		scr_log_print (LPRINT_LOGNORM, "%s: %s", domain, message);
 }
 #endif
@@ -1749,7 +1756,7 @@
 	lua_guard_init   (lua);
 
 	{
-		char *initfile = expand_filename (settings_opt_get ("lua_init_filename"));
+		char *initfile = expand_filename (settings_opt_get (OPT_MLUA_RC));
 
 		if (!initfile)
 			scr_log_print (LPRINT_LOGNORM, "lua: Cannot determine config file name");