76 mutt_error(
"Lua runtime panic: %s", lua_tostring(l, -1));
89 mutt_error(
"Lua runtime error: %s", lua_tostring(l, -1));
106 const struct Command *cmd = NULL;
109 if (lua_gettop(l) == 0)
111 luaL_error(l,
"Error command argument required.");
118 luaL_error(l,
"Error command %s not found.", lua_tostring(l, 1));
122 for (
int i = 2; i <= lua_gettop(l); i++)
128 if (cmd->
parse(token, buf, cmd->
data, err))
130 luaL_error(l,
"NeoMutt error: %s",
buf_string(err));
155 const char *param = lua_tostring(l, -2);
166 my_cdef.
name = param;
174 luaL_error(l,
"NeoMutt parameter not found %s", param);
195 const char *value = lua_tostring(l, -1);
196 size_t val_size = lua_rawlen(l, -1);
211 const intptr_t value = lua_tointeger(l, -1);
219 const intptr_t value = lua_toboolean(l, -1);
226 luaL_error(l,
"Unsupported NeoMutt parameter type %d for %s",
DTYPE(cdef->
type), param);
243 const char *param = lua_tostring(l, -1);
250 luaL_error(l,
"NeoMutt parameter not found %s", param);
283 lua_pushinteger(l, (
unsigned char) 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 = {}");
443 *l = luaL_newstate();
447 mutt_error(
_(
"Error: Couldn't load the lua interpreter"));
507 buf_printf(err,
_(
"%s: too many arguments"),
"source");
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
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.
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
CommandResult
Error codes for command_t parse functions.
@ MUTT_CMD_SUCCESS
Success: Command worked.
@ MUTT_CMD_ERROR
Error: Can't help the user.
@ MUTT_CMD_WARNING
Warning: Help given to the user.
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.
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
size_t commands_array(struct Command **first)
Get Commands array.
struct Command * command_get(const char *s)
Get a Command by its name.
Convenience wrapper for the core headers.
enum CommandResult mutt_lua_source_file(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'lua-source' command - Implements Command::parse() -.
enum CommandResult mutt_lua_parse(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'lua' command - Implements Command::parse() -.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
#define mutt_array_size(x)
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.
static int lua_mutt_enter(lua_State *l)
Execute NeoMutt config from Lua.
static int lua_mutt_message(lua_State *l)
Display a message in Neomutt.
static void luaopen_mutt(lua_State *l)
Expose a 'Mutt' object to the Lua interpreter.
void mutt_lua_init(void)
Setup feature commands.
static void lua_expose_command(lua_State *l, const struct Command *cmd)
Expose a NeoMutt command to the Lua interpreter.
static bool lua_init(lua_State **l)
Initialise a Lua State.
static int handle_panic(lua_State *l)
Handle a panic in the Lua interpreter.
static int lua_mutt_call(lua_State *l)
Call a NeoMutt command by name.
static int handle_error(lua_State *l)
Handle an error in the Lua interpreter.
static int lua_mutt_get(lua_State *l)
Get a NeoMutt variable.
static lua_State * LuaState
Global Lua State.
static const luaL_Reg LuaMuttCommands[]
List of Lua commands to register.
static int lua_mutt_error(lua_State *l)
Display an error in Neomutt.
static const struct Command LuaCommands[]
List of NeoMutt commands to register.
static int luaopen_mutt_decl(lua_State *l)
Declare some NeoMutt types to the Lua interpreter.
static int lua_mutt_set(lua_State *l)
Set a NeoMutt variable.
Integrated Lua scripting.
const char * mutt_make_version(void)
Generate the NeoMutt version string.
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.
char * dptr
Current read/write position.
char * data
Pointer to data.
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 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