make lua packages interfaces be *.li.
[apps/madmutt.git] / lib-lua / runtime.c
index f570b55..ac724af 100644 (file)
@@ -20,7 +20,8 @@
 #include <lib-lib/lib-lib.h>
 #include <lib-lua/lib-lua.h>
 
 #include <lib-lib/lib-lib.h>
 #include <lib-lua/lib-lua.h>
 
-#include <alias.h>
+#include "../alias.h"
+#include "../mutt.h"
 
 static lua_State *L;
 
 
 static lua_State *L;
 
@@ -83,3 +84,32 @@ quadopt_t luaM_checkquadopt(lua_State *Ls, int narg)
     return i;
 }
 
     return i;
 }
 
+const char *luaM_checkrx(lua_State *Ls, int narg)
+{
+    const char *s = luaL_checkstring(Ls, narg);
+    char buf[STRING];
+
+    if (rx_validate(s, buf, ssizeof(buf))) {
+        s = lua_pushfstring(Ls, "invalid regexp: `%s'", buf);
+        luaL_argerror(Ls, narg, s);
+        return NULL;
+    }
+
+    return s;
+}
+
+char *luaM_pathnew(const char *val)
+{
+    char path[PATH_MAX];
+    _mutt_expand_path(path, sizeof(path), val, 0);
+    return m_strdup(path);
+}
+
+rx_t *luaM_rxnew(const char *val)
+{
+    if (m_strisempty(val))
+        val = ".";
+
+    return rx_compile(val, mutt_which_case(val));
+}
+