lua.c
changeset 151 5d90caa7fb2c
parent 148 b222f4d111d9
child 152 0cf6c938ac03
--- a/lua.c	Sat Mar 05 18:36:28 2016 +0200
+++ b/lua.c	Thu Mar 17 23:17:00 2016 +0200
@@ -196,7 +196,7 @@
 	{ NULL,     -1 },
 };
 
-/// main.yesno
+/// mcabber.yesno
 /// According to yes or no ansvers returns true or false.
 /// If ansver is not recognized, returns nil.
 /// A: anything (string expected)
@@ -217,8 +217,8 @@
 	return 1;
 }
 
-/// main.version
-/// Returns information about mcabber version
+/// mcabber.version
+/// Returns table with information about mcabber  version
 /// R: table
 static int lua_main_version (lua_State *L)
 {
@@ -263,7 +263,7 @@
 	{ NULL,      0                   },
 };
 
-/// main.log
+/// mcabber.log
 /// Prints message to log.
 /// Note: most likely you need notutf8 flag enabled.
 /// A: log message type, message, message...
@@ -287,8 +287,8 @@
 	lua_settable (L, -3);
 }
 
-/// main.option
-/// Sets or gets value of mcabber option.
+/// mcabber.option
+/// Sets or gets value of given mcabber config option.
 /// You can specify nil as a value to delete option.
 /// If you omit option name, it returns hash table of all options.
 /// A: string (option name, optional), string (value, optional)
@@ -325,7 +325,7 @@
 	}
 }
 
-/// main.alias
+/// mcabber.alias
 /// Sets or gets alias.
 /// You can specify nil as a command to delete alias.
 /// If you omit alias name, it will return hash table of all aliases.
@@ -366,7 +366,7 @@
 	}
 }
 
-/// main.bind
+/// mcabber.bind
 /// Sets or gets binding.
 /// You can specify nil as a command to unbind key.
 /// If you omit keycode, it will return hash table of all bindings.
@@ -405,7 +405,7 @@
 	}
 }
 
-/// main.fileoption
+/// mcabber.fileoption
 /// Gets option, expanding it as filename.
 /// A: string (option name)
 /// R: string (expanded option value) or nil
@@ -421,7 +421,7 @@
 }
 
 #ifdef LLM_CONNECTION_ENABLE
-/// main.connection
+/// mcabber.connection
 /// Returns lightuserdata of mcabber's loudmouth connection.
 /// This can be very useful with lua-loudmouth, and not much otherwise.
 /// R: lightuserdata or nil
@@ -435,7 +435,7 @@
 }
 #endif
 
-/// main.print_info
+/// mcabber.print_info
 /// Prints a system message to buddy's window.
 /// A: string (jid), string (message)
 static int lua_main_print_info (lua_State *L)
@@ -450,7 +450,7 @@
 	return 0;
 }
 
-/// main.beep
+/// mcabber.beep
 /// Beeps with system speaker.
 static int lua_main_beep (lua_State *L)
 {
@@ -458,8 +458,9 @@
 	return 0;
 }
 
-/// main.run
-/// Runs specified mcabber command.
+/// mcabber.run
+/// Executes given string as a mcabber  command.
+/// Note: You should omit '/' in the beginning.
 /// A: string
 static int lua_main_run (lua_State *L)
 {
@@ -467,7 +468,7 @@
 	return 0;
 }
 
-/// main.status
+/// mcabber.status
 /// Returns your current status.
 /// R: string (status letter), string (status message)
 static int lua_main_status (lua_State *L)
@@ -489,7 +490,7 @@
 	g_free (jid);
 }
 
-/// main.roster
+/// mcabber.roster
 /// Returns array of jids of buddies in roster.
 /// R: table
 static int lua_main_roster (lua_State *L)
@@ -499,7 +500,7 @@
 	return 1;
 }
 
-/// main.current_buddy
+/// mcabber.current_buddy
 /// Returns jid of current selected buddy or sets current buddy to buddy with specified jid.
 /// A: string (optional)
 /// R: string (optional)
@@ -520,7 +521,7 @@
 	}
 }
 
-/// main.full_jid
+/// mcabber.full_jid
 /// Returns full jid (with current resource) of specified buddy (or current, if not specified).
 /// Note, that if there are no resources online, it will return just what it got.
 /// A: string (jid, optional)
@@ -585,7 +586,7 @@
 	g_free (resource);
 }
 
-/// main.buddy_info
+/// mcabber.buddy_info
 /// Returns a hash table with information on specified buddy.
 /// Table contains fields type, name, onserver and resources (which points to resources table).
 /// A: string (jid)
@@ -633,7 +634,7 @@
 
 GSList *lua_added_features = NULL;
 
-/// main.add_feature
+/// mcabber.add_feature
 /// Adds xmlns to disco#info features list.
 /// A: string (xmlns)
 static int lua_main_add_feature (lua_State *L)
@@ -644,7 +645,7 @@
 	return 0;
 }
 
-/// main.del_feature
+/// mcabber.del_feature
 /// Removes xmlns from disco#info features list.
 /// A: stirng (xmlns)
 static int lua_main_del_feature (lua_State *L)
@@ -713,7 +714,7 @@
 	}
 }
 
-/// main.event
+/// mcabber.event
 /// Creates new event. If called without arguments, returns event id list.
 /// A: event function (optional), string (event id), string (description, optional), integer (expiration timeout, optional)
 /// R: string (event id) or nothing (creation error) or table (list of event names)
@@ -966,7 +967,7 @@
 	}
 }
 
-/// main.parse_args
+/// mcabber.parse_args
 /// Function to parse command argument string to command arguments table.
 /// A: string
 /// R: table
@@ -976,7 +977,7 @@
 	return 1;
 }
 
-/// main.add_category
+/// mcabber.add_category
 /// Adds completion category.
 /// A: table (values are used as words for completion, optional), argument enum value (completion sorting order, optional)
 /// R: integer (category id, in fact completion type) or nil
@@ -1013,7 +1014,7 @@
 	return 1;
 }
 
-/// main.del_category
+/// mcabber.del_category
 /// Removes completion category.
 /// A: integer (category id)
 static int lua_main_del_category (lua_State *L)
@@ -1024,7 +1025,7 @@
 	return 0;
 }
 
-/// main.add_completion
+/// mcabber.add_completion
 /// Adds word to a completion list.
 /// A: integer (completion group id), string (word)
 static int lua_main_add_completion (lua_State *L)
@@ -1036,7 +1037,7 @@
 	return 0;
 }
 
-/// main.del_completion
+/// mcabber.del_completion
 /// Removes word from a completion list.
 /// A: integer (completion group id), string (word)
 static int lua_main_del_completion (lua_State *L)
@@ -1048,9 +1049,10 @@
 	return 0;
 }
 
-/// main.command
-/// Associates mcabber command name and lua function.
-/// As a completion you can also specify a string name (see completion type) instead of table, for non-builtin, you can just pass integer id.
+/// mcabber.command
+/// Associates mcabber  command name with given lua function.
+/// As a completion you can also specify a string name (see completion type) instead of table.
+/// For third-party completions you can just pass integer id.
 /// Note, that for now there are no way to unregister completion group, so, resources can be exausted easily.
 /// Also note, that it ignores keys in a completion table.
 /// A: string (command name), command function, boolean (parse args flag, optional), table (completions, optional)/completion type (or integer comletion group id, optional)
@@ -1206,7 +1208,7 @@
 	return ret;
 }
 
-/// main.timer
+/// mcabber.timer
 /// Creates new timer function, that will be called periodically.
 /// A: integer (interval, seconds), timer function
 static int lua_main_timer (lua_State *L)
@@ -1292,7 +1294,7 @@
 	return ret;
 }
 
-/// main.bgread
+/// mcabber.bgread
 /// Runs specified command and passes its output to a given function.
 /// A: string (command), background reading function
 static int lua_main_bgread (lua_State *L)
@@ -1422,7 +1424,7 @@
 	return ret;
 }
 
-/// main.hook_run
+/// mcabber.hook_run
 /// Runs handlers for given hook with supplied arguments.
 /// A: string (hook name), table (hook arguments)
 /// R: return enum field (hook handler result)
@@ -1471,7 +1473,7 @@
 	return 1;
 }
 
-/// main.hook
+/// mcabber.hook
 /// Installs hook handler, returns an object, that you need to keep until
 /// hook handling is no more needed.
 /// A: string (hook name), hook function, integer (priority, optional)
@@ -1595,7 +1597,7 @@
 	}
 }
 
-/// main.add_guard
+/// mcabber.add_guard
 /// Installs option guard for given option.
 /// A: string ( option name ), guard function
 /// R: boolean ( success )
@@ -1616,7 +1618,7 @@
 	return 1;
 }
 
-/// main.del_guard
+/// mcabber.del_guard
 /// Removes option guard from given option.
 /// By default, lua will refuse to remove guards, not installed
 /// by lua. Still, you can force guard removal.
@@ -1779,7 +1781,11 @@
 
 	lua_newtable(lua);
 	luaL_setfuncs (lua, lua_reg_main, 0);
+#ifdef COMPAT_0_0_4
+	lua_pushvalue (lua, -1);
 	lua_setglobal (lua, "main");
+#endif
+	lua_setglobal (lua, "mcabber");
 	lua_register (lua, "dopath", lua_global_dopath);
 	lua_register (lua, "print",  lua_global_print );