From: Pierre Habouzit Date: Sun, 1 Apr 2007 22:00:33 +0000 (+0200) Subject: implement folder-hooks as a lua callback. yipeeeeeeeeeeeh X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=4fb2fb9b1c03ad9ffd59ff86f7eaa697e46ef49d implement folder-hooks as a lua callback. yipeeeeeeeeeeeh Signed-off-by: Pierre Habouzit --- diff --git a/globals.h b/globals.h index 38438e2..7f6cf96 100644 --- a/globals.h +++ b/globals.h @@ -36,7 +36,6 @@ WHERE char *EditorHeaders; WHERE char *FileCharset; WHERE char *FolderFormat; WHERE char *ForwFmt; -WHERE char *Fqdn; WHERE char *HdrFmt; WHERE char *ImapAuthenticators INITVAL (NULL); diff --git a/hook.c b/hook.c index a84dc00..3c3c739 100644 --- a/hook.c +++ b/hook.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -256,6 +257,20 @@ void mutt_folder_hook (char *path) p_delete(&token.data); current_hook_type = 0; + + { + lua_State *L = luaM_getruntime(); + lua_getfield(L, LUA_GLOBALSINDEX, "MCore"); + lua_getfield(L, -1, "folder_hook"); + lua_remove(L, -2); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, LastFolder); + lua_pushstring(L, CurrentFolder); + lua_pcall(L, 2, 0, 0); + } else { + lua_pop(L, 1); + } + } } char *mutt_find_hook (int type, const char *pat) @@ -406,3 +421,5 @@ void mutt_account_hook (const char *url) p_delete(&token.data); } + +/* vim:set ft=c: */ diff --git a/lib-lua/lib-lua.h b/lib-lua/lib-lua.h index 3adc746..c4e981f 100644 --- a/lib-lua/lib-lua.h +++ b/lib-lua/lib-lua.h @@ -42,6 +42,8 @@ typedef enum quadopt_t { void luaM_initialize(void); void luaM_shutdown(void); +lua_State *luaM_getruntime(void); + int luaM_dofile(const char *filename); int luaM_wrap(void (*errfun)(const char *fmt, ...) __attribute__((format(printf, 1, 2))), diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index 6023ae6..f0e9093 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -61,6 +61,10 @@ void luaM_shutdown(void) lua_close(L); } +lua_State *luaM_getruntime(void) +{ + return L; +} int luaM_dofile(const char *filename) {