67 mutt_error(
"Lua runtime panic: %s", lua_tostring(l, -1));
80 mutt_error(
"Lua runtime error: %s", lua_tostring(l, -1));
97 const struct Command *cmd = NULL;
100 if (lua_gettop(l) == 0)
102 luaL_error(l,
"Error command argument required");
109 luaL_error(l,
"Error command %s not found", lua_tostring(l, 1));
113 for (
int i = 2; i <= lua_gettop(l); i++)
120 if (cmd->
parse(token, buf, cmd->
data, err))
122 luaL_error(l,
"NeoMutt error: %s",
buf_string(err));
147 const char *param = lua_tostring(l, -2);
158 my_cdef.
name = param;
166 luaL_error(l,
"NeoMutt parameter not found %s", param);
188 const char *value = lua_tostring(l, -1);
189 size_t val_size = lua_rawlen(l, -1);
205 const intptr_t value = lua_tointeger(l, -1);
213 const intptr_t value = lua_toboolean(l, -1);
220 luaL_error(l,
"Unsupported NeoMutt parameter type %d for %s",
238 const char *param = lua_tostring(l, -1);
245 luaL_error(l,
"NeoMutt parameter not found %s", param);
280 lua_pushinteger(l, (
unsigned char) cdef->
var);
283 lua_pushinteger(l, (
signed long) cdef->
var);
286 lua_pushinteger(l, (
signed short) cdef->
var);
289 lua_pushboolean(l, (
bool) cdef->
var);
292 luaL_error(l,
"NeoMutt parameter type %d unknown for %s", cdef->
type, param);
312 luaL_error(l,
"NeoMutt error: %s",
buf_string(err));
337 const char *msg = lua_tostring(l, -1);
351 const char *msg = lua_tostring(l, -1);
364 char buf[1024] = { 0 };
365 snprintf(buf,
sizeof(buf),
"mutt.command.%s = function (...); mutt.call('%s', ...); end",
367 (void) luaL_dostring(l, buf);
401 int lib_idx = lua_gettop(l);
404 lua_pushstring(l,
"VERSION"); lua_pushstring(l,
mutt_make_version()); lua_settable(l, lib_idx);
405 lua_pushstring(l,
"QUAD_YES"); lua_pushinteger(l,
MUTT_YES); lua_settable(l, lib_idx);
406 lua_pushstring(l,
"QUAD_NO"); lua_pushinteger(l,
MUTT_NO); lua_settable(l, lib_idx);
407 lua_pushstring(l,
"QUAD_ASKYES"); lua_pushinteger(l,
MUTT_ASKYES); lua_settable(l, lib_idx);
408 lua_pushstring(l,
"QUAD_ASKNO"); lua_pushinteger(l,
MUTT_ASKNO); lua_settable(l, lib_idx);
421 (void) luaL_dostring(l,
"mutt.command = {}");
423 const struct Command **cp = NULL;
426 const struct Command *cmd = *cp;
445 *l = luaL_newstate();
449 mutt_error(
_(
"Error: Couldn't load the lua interpreter"));
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
size_t escape_string(struct Buffer *buf, const char *src)
Write a string to a buffer, escaping special characters.
Convenience wrapper for the config headers.
struct HashElem * cs_create_variable(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Create and register one config item.
#define CSR_SUCCESS
Action completed successfully.
const struct Command * commands_get(struct CommandArray *ca, const char *name)
Get a Command by its name.
Convenience wrapper for the core headers.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
lua_State * LuaState
Global Lua State.
Integrated Lua scripting.
bool lua_init_state(lua_State **l)
Initialise a Lua State.
static int lua_expose_commands(lua_State *l)
Declare some NeoMutt types to the Lua interpreter.
static int lua_cb_global_set(lua_State *l)
Set a NeoMutt variable.
static void lua_expose_mutt(lua_State *l)
Expose a 'Mutt' object to the Lua interpreter.
static void lua_expose_command(lua_State *l, const struct Command *cmd)
Expose a NeoMutt command to the Lua interpreter.
static int lua_cb_global_message(lua_State *l)
Display a message in NeoMutt.
static int lua_handle_panic(lua_State *l)
Handle a panic in the Lua interpreter.
static int lua_cb_global_error(lua_State *l)
Display an error in NeoMutt.
static const luaL_Reg LuaMuttCommands[]
List of Lua commands to register.
static int lua_cb_global_enter(lua_State *l)
Execute NeoMutt config from Lua.
static int lua_cb_global_get(lua_State *l)
Get a NeoMutt variable.
static int lua_handle_error(lua_State *l)
Handle an error in the Lua interpreter.
static int lua_cb_global_call(lua_State *l)
Call a NeoMutt command by name.
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Some miscellaneous functions.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
@ MUTT_ASKNO
Ask the user, defaulting to 'No'.
@ MUTT_NO
User answered 'No', or assume 'No'.
@ MUTT_ASKYES
Ask the user, defaulting to 'Yes'.
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
enum CommandResult parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
String manipulation buffer.
enum CommandResult(* parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
intptr_t data
Data or flags to pass to the command.
const char * name
Name of the command.
const char * name
User-visible name.
intptr_t var
Storage for the variable.
uint32_t type
Variable type, e.g. DT_STRING.
struct ConfigSet * cs
Parent ConfigSet.
The item stored in a Hash Table.
int type
Type of data stored in Hash Table, e.g. DT_STRING.
void * data
User-supplied data.
Container for Accounts, Notifications.
struct CommandArray commands
NeoMutt commands.
struct ConfigSubset * sub
Inherited config items.
int cs_subset_he_string_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
int cs_subset_he_native_set(const struct ConfigSubset *sub, struct HashElem *he, intptr_t value, struct Buffer *err)
Natively set the value of a HashElem config item.
int cs_subset_he_string_set(const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
@ DT_SLIST
a list of strings
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
@ DT_MYVAR
a user-defined variable (my_foo)
@ DT_MBTABLE
multibyte char table
@ DT_ADDRESS
e-mail address
@ DT_REGEX
regular expressions
@ DT_PATH
a path to a file/directory
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Display version and copyright about NeoMutt.