NeoMutt  2018-07-16 +952-a2da0a
Teaching an old dog new tricks
DOXYGEN
mutt_lua.c File Reference

Integrated Lua scripting. More...

#include "config.h"
#include <lauxlib.h>
#include <limits.h>
#include <lua.h>
#include <lualib.h>
#include <stdbool.h>
#include <stdio.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "email/lib.h"
#include "mutt.h"
#include "mutt_lua.h"
#include "globals.h"
#include "mutt_commands.h"
#include "mutt_options.h"
#include "muttlib.h"
#include "mx.h"
#include "myvar.h"
+ Include dependency graph for mutt_lua.c:

Go to the source code of this file.

Macros

#define lua_add_lib_member(LUA, TABLE, KEY, VALUE, DATATYPE_HANDLER)
 

Functions

static int handle_panic (lua_State *l)
 Handle a panic in the Lua interpreter. More...
 
static int handle_error (lua_State *l)
 Handle an error in the Lua interpreter. More...
 
static int lua_mutt_call (lua_State *l)
 Call a NeoMutt command by name. More...
 
static int lua_mutt_set (lua_State *l)
 Set a NeoMutt variable. More...
 
static int lua_mutt_get (lua_State *l)
 Get a NeoMutt variable. More...
 
static int lua_mutt_enter (lua_State *l)
 Execute NeoMutt config from Lua. More...
 
static int lua_mutt_message (lua_State *l)
 Display a message in Neomutt. More...
 
static int lua_mutt_error (lua_State *l)
 Display an error in Neomutt. More...
 
static void lua_expose_command (void *p, const struct Command *cmd)
 Expose a NeoMutt command to the Lua interpreter. More...
 
static int luaopen_mutt_decl (lua_State *l)
 Declare some NeoMutt types to the Lua interpreter. More...
 
static void luaopen_mutt (lua_State *l)
 Expose a 'Mutt' object to the Lua interpreter. More...
 
static bool lua_init (lua_State **l)
 Initialise a Lua State. More...
 
int mutt_lua_parse (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'lua' command - Implements command_t. More...
 
int mutt_lua_source_file (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'lua-source' command - Implements command_t. More...
 

Variables

static const luaL_Reg luaMuttDecl []
 
lua_State * Lua = NULL
 

Detailed Description

Integrated Lua scripting.

Authors
  • Richard Russon
  • Bernard Pratz

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.c.

Macro Definition Documentation

#define lua_add_lib_member (   LUA,
  TABLE,
  KEY,
  VALUE,
  DATATYPE_HANDLER 
)
Value:
lua_pushstring(LUA, KEY); \
DATATYPE_HANDLER(LUA, VALUE); \
lua_settable(LUA, TABLE);

Definition at line 375 of file mutt_lua.c.

Function Documentation

static int handle_panic ( lua_State *  l)
static

Handle a panic in the Lua interpreter.

Parameters
lLua State
Return values
-1Always

Definition at line 54 of file mutt_lua.c.

55 {
56  mutt_debug(1, "lua runtime panic: %s\n", lua_tostring(l, -1));
57  mutt_error("Lua runtime panic: %s\n", lua_tostring(l, -1));
58  lua_pop(l, 1);
59  return -1;
60 }
#define mutt_error(...)
Definition: logging.h:88
#define mutt_debug(LEVEL,...)
Definition: logging.h:85

+ Here is the caller graph for this function:

static int handle_error ( lua_State *  l)
static

Handle an error in the Lua interpreter.

Parameters
lLua State
Return values
-1Always

Definition at line 67 of file mutt_lua.c.

68 {
69  mutt_debug(1, "lua runtime error: %s\n", lua_tostring(l, -1));
70  mutt_error("Lua runtime error: %s\n", lua_tostring(l, -1));
71  lua_pop(l, 1);
72  return -1;
73 }
#define mutt_error(...)
Definition: logging.h:88
#define mutt_debug(LEVEL,...)
Definition: logging.h:85

+ Here is the caller graph for this function:

static int lua_mutt_call ( lua_State *  l)
static

Call a NeoMutt command by name.

Parameters
lLua State
Return values
>=0Success
-1Error

Definition at line 81 of file mutt_lua.c.

82 {
83  mutt_debug(2, " * lua_mutt_call()\n");
84  struct Buffer token, expn, err;
85  char buffer[LONG_STRING] = "";
86  const struct Command *command = NULL;
87  int rc = 0;
88 
89  mutt_buffer_init(&token);
90  mutt_buffer_init(&expn);
91  mutt_buffer_init(&err);
92 
93  err.dsize = STRING;
94  err.data = mutt_mem_malloc(err.dsize);
95  err.data[0] = '\0';
96 
97  if (lua_gettop(l) == 0)
98  {
99  luaL_error(l, "Error command argument required.");
100  return -1;
101  }
102 
103  command = mutt_command_get(lua_tostring(l, 1));
104  if (!command)
105  {
106  luaL_error(l, "Error command %s not found.", lua_tostring(l, 1));
107  return -1;
108  }
109 
110  for (int i = 2; i <= lua_gettop(l); i++)
111  {
112  const char *s = lua_tostring(l, i);
113  mutt_str_strncat(buffer, sizeof(buffer), s, mutt_str_strlen(s));
114  mutt_str_strncat(buffer, sizeof(buffer), " ", 1);
115  }
116 
117  expn.data = buffer;
118  expn.dptr = buffer;
119  expn.dsize = mutt_str_strlen(buffer);
120 
121  if (command->func(&token, &expn, command->data, &err))
122  {
123  luaL_error(l, "NeoMutt error: %s", err.data);
124  rc = -1;
125  }
126  else
127  {
128  if (!lua_pushstring(l, err.data))
129  handle_error(l);
130  else
131  rc++;
132  }
133 
134  FREE(&err.data);
135 
136  return rc;
137 }
const struct Command * mutt_command_get(const char *s)
command_t func
Function to parse the command.
Definition: mutt_commands.h:46
String manipulation buffer.
Definition: buffer.h:33
A user-callable command.
Definition: mutt_commands.h:43
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
#define LONG_STRING
Definition: string2.h:36
char * mutt_str_strncat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:431
static int handle_error(lua_State *l)
Handle an error in the Lua interpreter.
Definition: mutt_lua.c:67
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:99
#define STRING
Definition: string2.h:35
#define FREE(x)
Definition: memory.h:46
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:66
unsigned long data
Data or flags to pass to the command.
Definition: mutt_commands.h:47

+ Here is the call graph for this function:

static int lua_mutt_set ( lua_State *  l)
static

Set a NeoMutt variable.

Parameters
lLua State
Return values
0Success
-1Error

Definition at line 145 of file mutt_lua.c.

146 {
147  const char *param = lua_tostring(l, -2);
148  mutt_debug(2, " * lua_mutt_set(%s)\n", param);
149 
150  if (mutt_str_startswith(param, "my_", CASE_MATCH))
151  {
152  const char *val = lua_tostring(l, -1);
153  myvar_set(param, val);
154  return 0;
155  }
156 
157  struct HashElem *he = cs_get_elem(Config, param);
158  if (!he)
159  {
160  luaL_error(l, "NeoMutt parameter not found %s", param);
161  return -1;
162  }
163 
164  struct ConfigDef *cdef = he->data;
165 
166  int rc = 0;
167  struct Buffer *err = mutt_buffer_alloc(STRING);
168 
169  switch (DTYPE(cdef->type))
170  {
171  case DT_ADDRESS:
172  case DT_MBTABLE:
173  case DT_REGEX:
174  case DT_PATH:
175  case DT_COMMAND:
176  case DT_SORT:
177  case DT_STRING:
178  case DT_MAGIC:
179  {
180  const char *value = lua_tostring(l, -1);
181  int rv = cs_he_string_set(Config, he, value, err);
182  if (CSR_RESULT(rv) != CSR_SUCCESS)
183  rc = -1;
184  break;
185  }
186  case DT_NUMBER:
187  case DT_QUAD:
188  {
189  const intptr_t value = lua_tointeger(l, -1);
190  int rv = cs_he_native_set(Config, he, value, err);
191  if (CSR_RESULT(rv) != CSR_SUCCESS)
192  rc = -1;
193  break;
194  }
195  case DT_BOOL:
196  {
197  const intptr_t value = lua_toboolean(l, -1);
198  int rv = cs_he_native_set(Config, he, value, err);
199  if (CSR_RESULT(rv) != CSR_SUCCESS)
200  rc = -1;
201  break;
202  }
203  default:
204  luaL_error(l, "Unsupported NeoMutt parameter type %d for %s", DTYPE(cdef->type), param);
205  rc = -1;
206  break;
207  }
208 
209  mutt_buffer_free(&err);
210  return rc;
211 }
#define CSR_RESULT(x)
Definition: set.h:61
#define DT_REGEX
regular expressions
Definition: types.h:37
String manipulation buffer.
Definition: buffer.h:33
#define DT_SORT
sorting methods
Definition: types.h:38
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:39
Match case when comparing strings.
Definition: string2.h:69
#define DT_MBTABLE
multibyte char table
Definition: types.h:33
Config item definition.
Definition: set.h:160
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:36
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:42
struct Buffer * mutt_buffer_alloc(size_t size)
Create a new Buffer.
Definition: buffer.c:298
void mutt_buffer_free(struct Buffer **p)
Release a Buffer and its contents.
Definition: buffer.c:138
int cs_he_native_set(const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err)
Natively set the value of a HashElem config item.
Definition: set.c:750
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:192
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:45
void myvar_set(const char *var, const char *val)
Set the value of a "my_" variable.
Definition: myvar.c:60
#define DT_ADDRESS
e-mail address
Definition: types.h:27
#define DT_STRING
a string
Definition: types.h:39
#define DT_PATH
a pathname
Definition: types.h:35
#define DT_MAGIC
mailbox type
Definition: types.h:32
#define DT_COMMAND
a command
Definition: types.h:29
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:166
void * data
Definition: hash.h:46
unsigned int type
Variable type, e.g.
Definition: set.h:163
#define STRING
Definition: string2.h:35
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
#define DT_NUMBER
a number
Definition: types.h:34
#define DT_BOOL
boolean option
Definition: types.h:28
int cs_he_string_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:602

+ Here is the call graph for this function:

static int lua_mutt_get ( lua_State *  l)
static

Get a NeoMutt variable.

Parameters
lLua State
Return values
1Success
-1Error

Definition at line 219 of file mutt_lua.c.

220 {
221  const char *param = lua_tostring(l, -1);
222  mutt_debug(2, " * lua_mutt_get(%s)\n", param);
223 
224  if (mutt_str_startswith(param, "my_", CASE_MATCH))
225  {
226  const char *mv = myvar_get(param);
227  if (!mv)
228  {
229  luaL_error(l, "NeoMutt parameter not found %s", param);
230  return -1;
231  }
232 
233  lua_pushstring(l, mv);
234  return 1;
235  }
236 
237  struct HashElem *he = cs_get_elem(Config, param);
238  if (!he)
239  {
240  mutt_debug(2, " * error\n");
241  luaL_error(l, "NeoMutt parameter not found %s", param);
242  return -1;
243  }
244 
245  struct ConfigDef *cdef = he->data;
246 
247  switch (DTYPE(cdef->type))
248  {
249  case DT_ADDRESS:
250  case DT_COMMAND:
251  case DT_MAGIC:
252  case DT_MBTABLE:
253  case DT_PATH:
254  case DT_REGEX:
255  case DT_SORT:
256  case DT_STRING:
257  {
258  struct Buffer *value = mutt_buffer_alloc(STRING);
259  int rc = cs_he_string_get(Config, he, value);
260  if (CSR_RESULT(rc) != CSR_SUCCESS)
261  {
262  mutt_buffer_free(&value);
263  return -1;
264  }
265 
266  struct Buffer *escaped = mutt_buffer_alloc(STRING);
267  escape_string(escaped, value->data);
268  lua_pushstring(l, escaped->data);
269  mutt_buffer_free(&value);
270  mutt_buffer_free(&escaped);
271  return 1;
272  }
273  case DT_QUAD:
274  lua_pushinteger(l, *(unsigned char *) cdef->var);
275  return 1;
276  case DT_NUMBER:
277  lua_pushinteger(l, (signed short) *((unsigned long *) cdef->var));
278  return 1;
279  case DT_BOOL:
280  lua_pushboolean(l, *((bool *) cdef->var));
281  return 1;
282  default:
283  luaL_error(l, "NeoMutt parameter type %d unknown for %s", cdef->type, param);
284  return -1;
285  }
286 }
#define CSR_RESULT(x)
Definition: set.h:61
#define DT_REGEX
regular expressions
Definition: types.h:37
String manipulation buffer.
Definition: buffer.h:33
#define DT_SORT
sorting methods
Definition: types.h:38
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:39
Match case when comparing strings.
Definition: string2.h:69
#define DT_MBTABLE
multibyte char table
Definition: types.h:33
Config item definition.
Definition: set.h:160
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:36
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:42
struct Buffer * mutt_buffer_alloc(size_t size)
Create a new Buffer.
Definition: buffer.c:298
void mutt_buffer_free(struct Buffer **p)
Release a Buffer and its contents.
Definition: buffer.c:138
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:192
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:45
#define DT_ADDRESS
e-mail address
Definition: types.h:27
#define DT_STRING
a string
Definition: types.h:39
#define DT_PATH
a pathname
Definition: types.h:35
#define DT_MAGIC
mailbox type
Definition: types.h:32
char * data
pointer to data
Definition: buffer.h:35
#define DT_COMMAND
a command
Definition: types.h:29
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:42
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:166
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:680
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:165
unsigned int type
Variable type, e.g.
Definition: set.h:163
#define STRING
Definition: string2.h:35
size_t escape_string(struct Buffer *buf, const char *src)
Write a string to a buffer, escaping special characters.
Definition: dump.c:51
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
#define DT_NUMBER
a number
Definition: types.h:34
#define DT_BOOL
boolean option
Definition: types.h:28

+ Here is the call graph for this function:

static int lua_mutt_enter ( lua_State *  l)
static

Execute NeoMutt config from Lua.

Parameters
lLua State
Return values
>=0Success
-1Error

Definition at line 294 of file mutt_lua.c.

295 {
296  mutt_debug(2, " * lua_mutt_enter()\n");
297  struct Buffer token, err;
298  char *buffer = mutt_str_strdup(lua_tostring(l, -1));
299  int rc = 0;
300 
301  mutt_buffer_init(&err);
302  mutt_buffer_init(&token);
303 
304  err.dsize = STRING;
305  err.data = mutt_mem_malloc(err.dsize);
306 
307  if (mutt_parse_rc_line(buffer, &token, &err))
308  {
309  luaL_error(l, "NeoMutt error: %s", err.data);
310  rc = -1;
311  }
312  else
313  {
314  if (!lua_pushstring(l, err.data))
315  handle_error(l);
316  else
317  rc++;
318  }
319 
320  FREE(&buffer);
321  FREE(&err.data);
322 
323  return rc;
324 }
int mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3119
String manipulation buffer.
Definition: buffer.h:33
static int handle_error(lua_State *l)
Handle an error in the Lua interpreter.
Definition: mutt_lua.c:67
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:99
#define STRING
Definition: string2.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:384
#define FREE(x)
Definition: memory.h:46
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:66

+ Here is the call graph for this function:

static int lua_mutt_message ( lua_State *  l)
static

Display a message in Neomutt.

Parameters
lLua State
Return values
0Always

Definition at line 331 of file mutt_lua.c.

332 {
333  mutt_debug(2, " * lua_mutt_message()\n");
334  const char *msg = lua_tostring(l, -1);
335  if (msg)
336  mutt_message(msg);
337  return 0;
338 }
#define mutt_message(...)
Definition: logging.h:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
static int lua_mutt_error ( lua_State *  l)
static

Display an error in Neomutt.

Parameters
lLua State
Return values
0Always

Definition at line 345 of file mutt_lua.c.

346 {
347  mutt_debug(2, " * lua_mutt_error()\n");
348  const char *msg = lua_tostring(l, -1);
349  if (msg)
350  mutt_error(msg);
351  return 0;
352 }
#define mutt_error(...)
Definition: logging.h:88
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
static void lua_expose_command ( void *  p,
const struct Command cmd 
)
static

Expose a NeoMutt command to the Lua interpreter.

Parameters
pLua state
cmdNeoMutt Command

Definition at line 359 of file mutt_lua.c.

360 {
361  lua_State *l = (lua_State *) p;
362  char buf[LONG_STRING];
363  snprintf(buf, sizeof(buf), "mutt.command.%s = function (...); mutt.call('%s', ...); end",
364  cmd->name, cmd->name);
365  (void) luaL_dostring(l, buf);
366 }
const char * name
Name of the command.
Definition: mutt_commands.h:45
#define LONG_STRING
Definition: string2.h:36

+ Here is the caller graph for this function:

static int luaopen_mutt_decl ( lua_State *  l)
static

Declare some NeoMutt types to the Lua interpreter.

Parameters
lLua State
Return values
1Always

Definition at line 385 of file mutt_lua.c.

386 {
387  mutt_debug(2, " * luaopen_mutt()\n");
388  luaL_newlib(l, luaMuttDecl);
389  int lib_idx = lua_gettop(l);
390  /* table_idx, key value, value's type */
391  lua_add_lib_member(l, lib_idx, "VERSION", mutt_make_version(), lua_pushstring);
392  lua_add_lib_member(l, lib_idx, "QUAD_YES", MUTT_YES, lua_pushinteger);
393  lua_add_lib_member(l, lib_idx, "QUAD_NO", MUTT_NO, lua_pushinteger);
394  lua_add_lib_member(l, lib_idx, "QUAD_ASKYES", MUTT_ASKYES, lua_pushinteger);
395  lua_add_lib_member(l, lib_idx, "QUAD_ASKNO", MUTT_ASKNO, lua_pushinteger);
396  return 1;
397 }
#define lua_add_lib_member(LUA, TABLE, KEY, VALUE, DATATYPE_HANDLER)
Definition: mutt_lua.c:375
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
Ask the user, defaulting to &#39;Yes&#39;.
Definition: quad.h:41
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
Ask the user, defaulting to &#39;No&#39;.
Definition: quad.h:40
static const luaL_Reg luaMuttDecl[]
Definition: mutt_lua.c:368
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition: muttlib.c:1492

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void luaopen_mutt ( lua_State *  l)
static

Expose a 'Mutt' object to the Lua interpreter.

Parameters
lLua State

Definition at line 403 of file mutt_lua.c.

404 {
405  luaL_requiref(l, "mutt", luaopen_mutt_decl, 1);
406  (void) luaL_dostring(l, "mutt.command = {}");
408 }
static int luaopen_mutt_decl(lua_State *l)
Declare some NeoMutt types to the Lua interpreter.
Definition: mutt_lua.c:385
void mutt_commands_apply(void *data, void(*application)(void *, const struct Command *))
static void lua_expose_command(void *p, const struct Command *cmd)
Expose a NeoMutt command to the Lua interpreter.
Definition: mutt_lua.c:359

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool lua_init ( lua_State **  l)
static

Initialise a Lua State.

Parameters
lLua State
Return values
trueIf successful

Definition at line 415 of file mutt_lua.c.

416 {
417  if (!l)
418  return false;
419  if (*l)
420  return true;
421 
422  mutt_debug(2, " * lua_init()\n");
423  *l = luaL_newstate();
424 
425  if (!*l)
426  {
427  mutt_error(_("Error: Couldn't load the lua interpreter"));
428  return false;
429  }
430 
431  lua_atpanic(*l, handle_panic);
432 
433  /* load various Lua libraries */
434  luaL_openlibs(*l);
435  luaopen_mutt(*l);
436 
437  return true;
438 }
static int handle_panic(lua_State *l)
Handle a panic in the Lua interpreter.
Definition: mutt_lua.c:54
#define _(a)
Definition: message.h:28
#define mutt_error(...)
Definition: logging.h:88
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
static void luaopen_mutt(lua_State *l)
Expose a &#39;Mutt&#39; object to the Lua interpreter.
Definition: mutt_lua.c:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_lua_parse ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)

Parse the 'lua' command - Implements command_t.

Definition at line 447 of file mutt_lua.c.

448 {
449  lua_init(&Lua);
450  mutt_debug(2, " * mutt_lua_parse(%s)\n", buf->data);
451 
452  if (luaL_dostring(Lua, s->dptr))
453  {
454  mutt_debug(2, " * %s -> failure\n", s->dptr);
455  mutt_buffer_printf(err, "%s: %s", s->dptr, lua_tostring(Lua, -1));
456  /* pop error message from the stack */
457  lua_pop(Lua, 1);
458  return -1;
459  }
460  mutt_debug(2, " * %s -> success\n", s->dptr);
461  return 2;
462 }
lua_State * Lua
Definition: mutt_lua.c:442
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:200
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:415
char * dptr
current read/write position
Definition: buffer.h:36
char * data
pointer to data
Definition: buffer.h:35
#define mutt_debug(LEVEL,...)
Definition: logging.h:85

+ Here is the call graph for this function:

int mutt_lua_source_file ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)

Parse the 'lua-source' command - Implements command_t.

Definition at line 467 of file mutt_lua.c.

469 {
470  mutt_debug(2, " * mutt_lua_source()\n");
471 
472  lua_init(&Lua);
473 
474  char path[PATH_MAX];
475 
476  if (mutt_extract_token(buf, s, 0) != 0)
477  {
478  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
479  return -1;
480  }
481  if (MoreArgs(s))
482  {
483  mutt_buffer_printf(err, _("%s: too many arguments"), "source");
484  return -1;
485  }
486  mutt_str_strfcpy(path, buf->data, sizeof(path));
487  mutt_expand_path(path, sizeof(path));
488 
489  if (luaL_dofile(Lua, path))
490  {
491  mutt_error(_("Couldn't source lua source: %s"), lua_tostring(Lua, -1));
492  lua_pop(Lua, 1);
493  return -1;
494  }
495  return 2;
496 }
lua_State * Lua
Definition: mutt_lua.c:442
#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:200
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:157
#define MoreArgs(buf)
Definition: buffer.h:44
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:415
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
#define PATH_MAX
Definition: mutt.h:46
char * dptr
current read/write position
Definition: buffer.h:36
char * data
pointer to data
Definition: buffer.h:35
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
#define mutt_error(...)
Definition: logging.h:88
#define mutt_debug(LEVEL,...)
Definition: logging.h:85

+ Here is the call graph for this function:

Variable Documentation

const luaL_Reg luaMuttDecl[]
static
Initial value:
= {
{ "set", lua_mutt_set }, { "get", lua_mutt_get },
{ "call", lua_mutt_call }, { "enter", lua_mutt_enter },
{ "print", lua_mutt_message }, { "message", lua_mutt_message },
{ "error", lua_mutt_error }, { NULL, NULL },
}
static int lua_mutt_set(lua_State *l)
Set a NeoMutt variable.
Definition: mutt_lua.c:145
static int lua_mutt_enter(lua_State *l)
Execute NeoMutt config from Lua.
Definition: mutt_lua.c:294
static int lua_mutt_message(lua_State *l)
Display a message in Neomutt.
Definition: mutt_lua.c:331
static int lua_mutt_call(lua_State *l)
Call a NeoMutt command by name.
Definition: mutt_lua.c:81
static int lua_mutt_error(lua_State *l)
Display an error in Neomutt.
Definition: mutt_lua.c:345
static int lua_mutt_get(lua_State *l)
Get a NeoMutt variable.
Definition: mutt_lua.c:219

Definition at line 368 of file mutt_lua.c.

lua_State* Lua = NULL

Definition at line 442 of file mutt_lua.c.