NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
mutt_lua.h File Reference

Integrated Lua scripting. More...

#include <stdint.h>
#include "mutt_commands.h"
+ Include dependency graph for mutt_lua.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

enum CommandResult mutt_lua_parse (struct Buffer *tmp, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua' command - Implements Command::parse() More...
 
enum CommandResult mutt_lua_source_file (struct Buffer *tmp, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua-source' command - Implements Command::parse() More...
 
void mutt_lua_init (void)
 Setup feature commands. More...
 

Detailed Description

Integrated Lua scripting.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file mutt_lua.h.

Function Documentation

◆ mutt_lua_parse()

enum CommandResult mutt_lua_parse ( struct Buffer tmp,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'lua' command - Implements Command::parse()

Definition at line 460 of file mutt_lua.c.

462 {
463  lua_init(&LuaState);
464  mutt_debug(LL_DEBUG2, " * mutt_lua_parse(%s)\n", buf->data);
465 
466  if (luaL_dostring(LuaState, s->dptr))
467  {
468  mutt_debug(LL_DEBUG2, " * %s -> failure\n", s->dptr);
469  mutt_buffer_printf(err, "%s: %s", s->dptr, lua_tostring(LuaState, -1));
470  /* pop error message from the stack */
471  lua_pop(LuaState, 1);
472  return MUTT_CMD_ERROR;
473  }
474  mutt_debug(LL_DEBUG2, " * %s -> success\n", s->dptr);
475  mutt_buffer_reset(s); // Clear the rest of the line
476  return MUTT_CMD_SUCCESS;
477 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
lua_State * LuaState
Definition: mutt_lua.c:375
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:424
Log at debug level 2.
Definition: logging.h:41
char * dptr
Current read/write position.
Definition: buffer.h:36
Success: Command worked.
Definition: mutt_commands.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:

◆ mutt_lua_source_file()

enum CommandResult mutt_lua_source_file ( struct Buffer tmp,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'lua-source' command - Implements Command::parse()

Definition at line 482 of file mutt_lua.c.

484 {
485  mutt_debug(LL_DEBUG2, " * mutt_lua_source()\n");
486 
487  lua_init(&LuaState);
488 
489  char path[PATH_MAX];
490 
491  if (mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS) != 0)
492  {
493  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
494  return MUTT_CMD_ERROR;
495  }
496  if (MoreArgs(s))
497  {
498  mutt_buffer_printf(err, _("%s: too many arguments"), "source");
499  return MUTT_CMD_WARNING;
500  }
501  mutt_str_copy(path, buf->data, sizeof(path));
502  mutt_expand_path(path, sizeof(path));
503 
504  if (luaL_dofile(LuaState, path))
505  {
506  mutt_error(_("Couldn't source lua source: %s"), lua_tostring(LuaState, -1));
507  lua_pop(LuaState, 1);
508  return MUTT_CMD_ERROR;
509  }
510  return MUTT_CMD_SUCCESS;
511 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
lua_State * LuaState
Definition: mutt_lua.c:375
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:128
#define MoreArgs(buf)
Definition: buffer.h:43
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:424
Log at debug level 2.
Definition: logging.h:41
#define PATH_MAX
Definition: mutt.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:394
char * dptr
Current read/write position.
Definition: buffer.h:36
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:716
#define mutt_error(...)
Definition: logging.h:84
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:70
+ Here is the call graph for this function:

◆ mutt_lua_init()

void mutt_lua_init ( void  )

Setup feature commands.

Definition at line 452 of file mutt_lua.c.

453 {
455 }
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:77
static const struct Command lua_commands[]
Definition: mutt_lua.c:55
+ Here is the caller graph for this function: