X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lua%2Fruntime.c;h=b90d460ec61f6be23b3d872241672ea21c7144f1;hp=ac724aff44e698b745f4a216e80fa6760e0a1992;hb=90f0c4dfb0480b5ce043c54f001d53ba6efc531b;hpb=05e61a9707a6da5c0bca77aa7c3c019a918494de diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index ac724af..b90d460 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -20,8 +20,13 @@ #include #include -#include "../alias.h" #include "../mutt.h" +#include "../alias.li" +#include "../buffy.li" +#include "../charset.li" +#include "../crypt.li" +#include "../score.li" +#include static lua_State *L; @@ -36,9 +41,15 @@ void luaM_initialize(void) {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, - {"MCore", luaopen_MCore}, + {"mod_core", luaopen_mod_core}, {"MTransport", luaopen_MTransport}, {"MAlias", luaopen_MAlias}, + {"mod_cset", luaopen_mod_cset}, + {"mod_mime", luaopen_mod_mime}, + {"mod_buffy", luaopen_mod_buffy}, + {"mod_ssl", luaopen_mod_ssl}, + {"mod_crypt", luaopen_mod_crypt}, + {"mod_score", luaopen_mod_score}, }; int i; @@ -56,6 +67,10 @@ void luaM_shutdown(void) lua_close(L); } +lua_State *luaM_getruntime(void) +{ + return L; +} int luaM_dofile(const char *filename) { @@ -75,8 +90,21 @@ int luaM_wrap(void (*errfun)(const char *fmt, ...), int status) quadopt_t luaM_checkquadopt(lua_State *Ls, int narg) { const char *s; - int i = luaL_checkinteger(Ls, narg); + int i; + if (lua_type(Ls, narg) == LUA_TSTRING) { + s = lua_tostring(Ls, narg); + switch (mlua_which_token(s, -1)) { + case LTK_YES: return M_YES; + case LTK_NO: return M_NO; + case LTK_ASK_YES: return M_ASKYES; + case LTK_ASK_NO: return M_ASKNO; + default: + break; + } + } + + i = luaL_checkinteger(Ls, narg); if (i & ~3) { s = lua_pushfstring(Ls, "int in [0-3] expected, got %d", i); return luaL_argerror(Ls, narg, s); @@ -84,6 +112,17 @@ quadopt_t luaM_checkquadopt(lua_State *Ls, int narg) return i; } +void luaM_pushquadopt(lua_State *Ls, int val) +{ + switch (val) { + case M_YES: return lua_pushstring(Ls, "yes"); + case M_NO: return lua_pushstring(Ls, "no"); + case M_ASKYES: return lua_pushstring(Ls, "ask-yes"); + case M_ASKNO: return lua_pushstring(Ls, "ask-no"); + default: return lua_pushnil(Ls); + } +} + const char *luaM_checkrx(lua_State *Ls, int narg) { const char *s = luaL_checkstring(Ls, narg); @@ -98,13 +137,6 @@ const char *luaM_checkrx(lua_State *Ls, int narg) 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)) @@ -113,3 +145,17 @@ rx_t *luaM_rxnew(const char *val) return rx_compile(val, mutt_which_case(val)); } +char *luaM_pathnew(const char *val) +{ + char path[_POSIX_PATH_MAX]; + _mutt_expand_path(path, sizeof(path), val, 0); + return m_strdup(path); +} + + +void luaM_pushaddr(lua_State *Ls, address_t *addr) +{ + char s[HUGE_STRING] = ""; + rfc822_addrcat(s, sizeof(s), addr, 0); + lua_pushstring(Ls, s); +}