implement folder-hooks as a lua callback. yipeeeeeeeeeeeh
[apps/madmutt.git] / hook.c
diff --git a/hook.c b/hook.c
index a84dc00..3c3c739 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -8,6 +8,7 @@
  */
 
 #include <lib-lib/lib-lib.h>
+#include <lib-lua/lib-lua.h>
 #include <lib-ui/curses.h>
 #include <lib-mx/mx.h>
 #include <lib-mx/compress.h>
@@ -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: */