2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2007 Pierre Habouzit
20 #include <lib-lib/lib-lib.h>
21 #include <lib-lua/lib-lua.h>
28 void luaM_initialize(void)
30 static const luaL_Reg lualibs[] = {
32 {LUA_OSLIBNAME, luaopen_os},
33 {LUA_LOADLIBNAME, luaopen_package},
34 {LUA_TABLIBNAME, luaopen_table},
35 {LUA_IOLIBNAME, luaopen_io},
36 {LUA_STRLIBNAME, luaopen_string},
37 {LUA_MATHLIBNAME, luaopen_math},
38 {LUA_DBLIBNAME, luaopen_debug},
39 {"MCore", luaopen_MCore},
40 {"MTransport", luaopen_MTransport},
41 {"MAlias", luaopen_MAlias},
47 for (i = 0; i < countof(lualibs); i++) {
48 lua_pushcfunction(L, lualibs[i].func);
49 lua_pushstring(L, lualibs[i].name);
54 void luaM_shutdown(void)
60 int luaM_dofile(const char *filename)
62 return luaL_dofile(L, filename);
65 int luaM_wrap(void (*errfun)(const char *fmt, ...), int status)
68 (*errfun)("-[lua]-: %s\n", lua_tostring(L, -1));
75 quadopt_t luaM_checkquadopt(lua_State *Ls, int narg)
78 int i = luaL_checkinteger(Ls, narg);
81 s = lua_pushfstring(Ls, "int in [0-3] expected, got %d", i);
82 return luaL_argerror(Ls, narg, s);
87 const char *luaM_checkrx(lua_State *Ls, int narg)
89 const char *s = luaL_checkstring(Ls, narg);
92 if (rx_validate(s, buf, ssizeof(buf))) {
93 s = lua_pushfstring(Ls, "invalid regexp: `%s'", buf);
94 luaL_argerror(Ls, narg, s);
101 char *luaM_pathnew(const char *val)
104 _mutt_expand_path(path, sizeof(path), val, 0);
105 return m_strdup(path);
108 rx_t *luaM_rxnew(const char *val)
110 if (m_strisempty(val))
113 return rx_compile(val, mutt_which_case(val));