Timers destruction
* timers destruction on unloading
* option to enable lm debug output
* some other options
--- a/TODO Mon Mar 16 01:04:49 2009 +0200
+++ b/TODO Mon Mar 16 04:06:02 2009 +0200
@@ -2,15 +2,16 @@
print should allow other types to be printed
finish roster list information
non-setting settings?
-mcabber_config_file uses option to set dir?
+mcabber_config_file uses option to set dir? eliminate main.config_file, use modules_dir option instead in lua paths?
do uninitialization of commands and features with objects?
help system accessors (needs major rewrite and planning)
-object access to roster and buddies
+object access to roster and buddies?
in mcabber add hook/call to also handle room status changes
well, so, mcabber will pass all arguments to hooks in utf. but do we really need to convert names to utf?
use glib filename charset conversion functions?
toggle routine should handle multiple status toggles
think about how tune notification should act on start/quit
-timers deinitialization on module unloading
clarify situation with disco, maybe it is due to this we are unable to receive pep events
+lm debug should be more flexible
+make bgread buffer size and timers priority either CMake definitions or mcabber options
--- a/examples/jobs.lua Mon Mar 16 01:04:49 2009 +0200
+++ b/examples/jobs.lua Mon Mar 16 04:06:02 2009 +0200
@@ -6,7 +6,7 @@
dopath 'saved_jobs.lua'
function save_jobs ()
- local h = io.open ( main.config_file ( 'saved_jobs.lua' ), "w" )
+ local h = io.open ( main.option ( 'lua_jobs_file' ), "w" )
if not h then
print ( 'Cannot open jobs file for writing!' )
return
--- a/examples/lua.rc Mon Mar 16 01:04:49 2009 +0200
+++ b/examples/lua.rc Mon Mar 16 04:06:02 2009 +0200
@@ -1,8 +1,18 @@
# lua function name to be called on hooks invocation
-set lua_hook_function = hook_handler
-set lua_init_filename = ~/.mcabber/mcabberrc.lua
+set lua_hook_function = hook_handler
+
+# initialization file to load
+set lua_init_filename = ~/.mcabber/mcabberrc.lua
+
+# lua-loudmouth debug output be shown in log
+set lua_lm_debug = 0
+
+# show notifications for pep events
+set lua_pep_notification = enable
+
+# XXX jobs file
+set lua_jobs_file = /home/isbear/.mcabber/saved_jobs.lua
+
load mcabber-lua
-# :(
-#lua dofile 'mcabberrc'
--- a/examples/xep0163.lua Mon Mar 16 01:04:49 2009 +0200
+++ b/examples/xep0163.lua Mon Mar 16 04:06:02 2009 +0200
@@ -117,7 +117,7 @@
function ( conn, mess )
local e = mess:child ( 'event' )
if e and e:attribute ( 'xmlns' ) == 'http://jabber.org/protocol/pubsub#event' then
- local enable = yesno ( main.option ( 'pep_notification' ) )
+ local enable = yesno ( main.option ( 'lua_pep_notification' ) )
if enable == false then
return true
end
--- a/main.c Mon Mar 16 01:04:49 2009 +0200
+++ b/main.c Mon Mar 16 04:06:02 2009 +0200
@@ -393,7 +393,9 @@
gpointer buddy;
} lua_state_and_buddy_t; // :)
-// expects table on top!
+/// resources table
+/// Hash table with resource name as keys and another hash tables as values.
+/// Inner tables contain resource-specific information: priority, status and message.
static void lua_buddy_resources_callback (gpointer resource, lua_state_and_buddy_t *d)
{
char *loc = from_utf8 (resource);
@@ -417,10 +419,7 @@
/// main.buddy_info
/// Returns a hash table with information on specified buddy.
-/// Table contains fields type, name, onserver and resources.
-/// Resources is also a hash table, that contains tables with information,
-/// specific for each resource. In each resource table there are fields
-/// priority, status and message.
+/// Table contains fields type, name, onserver and resources (which points to resources table).
/// A: string (jid)
/// R: table
static int lua_main_buddy_info (lua_State *L)
@@ -783,12 +782,16 @@
typedef struct {
int reference;
+ guint source;
lua_State *L;
} lua_timer_callback_t;
+static GSList *lua_timers = NULL;
+
static void lua_timer_callback_destroy (lua_timer_callback_t *cb)
{
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference);
+ lua_timers = g_slist_remove (lua_timers, (gpointer) cb->source);
luaL_free (cb->L, cb);
}
@@ -815,6 +818,7 @@
static int lua_main_timer (lua_State *L)
{
int interval = luaL_checkint (L, 1);
+ guint source;
lua_timer_callback_t *cb;
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
@@ -822,7 +826,10 @@
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
cb->L = L;
- g_timeout_add_seconds_full (LUA_TIMER_PRIORITY, interval, (GSourceFunc) lua_timer_callback, cb, (GDestroyNotify) lua_timer_callback_destroy);
+ source = g_timeout_add_seconds_full (LUA_TIMER_PRIORITY, interval, (GSourceFunc) lua_timer_callback, cb, (GDestroyNotify) lua_timer_callback_destroy);
+ cb->source = source;
+ lua_timers = g_slist_prepend (lua_timers, (gpointer) source);
+
return 0;
}
@@ -934,7 +941,8 @@
void lua_lm_log_handler (const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer ignore)
{
- scr_LogPrint (LPRINT_LOGNORM, "%s: %s", domain, message);
+ if (settings_opt_get_int ("lua_lm_debug"))
+ scr_LogPrint (LPRINT_LOGNORM, "%s: %s", domain, message);
}
#endif
@@ -1075,6 +1083,11 @@
return NULL;
}
+static void lua_timers_destroy (guint source, gpointer ignore)
+{
+ g_source_remove (source);
+}
+
static void lua_features_destroy (char *xmlns, gpointer ignore)
{
xmpp_del_feature (xmlns);
@@ -1107,6 +1120,10 @@
hk_del_handler ((hk_handler_t) lua_hook, lua);
+ g_slist_foreach (lua_timers, (GFunc) lua_timers_destroy, NULL);
+ g_slist_free (lua_timers);
+ lua_timers = NULL;
+
g_slist_foreach (lua_added_features, (GFunc) lua_features_destroy, NULL);
g_slist_free (lua_added_features);
lua_added_features = NULL;