X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lua%2Fruntime.c;h=923222bde7e2a97ad1dff82097d48cc7d9c860f0;hp=ac724aff44e698b745f4a216e80fa6760e0a1992;hb=1681dff7a1b69b0dad31d515c466439548b71f94;hpb=05e61a9707a6da5c0bca77aa7c3c019a918494de diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index ac724af..923222b 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -75,8 +75,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 +97,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);