NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
commands.c File Reference

Lua Commands. More...

#include "config.h"
#include <lauxlib.h>
#include <lua.h>
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "lib.h"
#include "parse/lib.h"
#include "muttlib.h"
+ Include dependency graph for commands.c:

Go to the source code of this file.

Macros

#define LUA_COMPAT_ALL
 
#define LUA_COMPAT_5_1
 

Functions

bool lua_init_state (lua_State **l)
 Initialise a Lua State.
 
enum CommandResult parse_lua (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'lua' command - Implements Command::parse() -.
 
enum CommandResult parse_lua_source (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'lua-source' command - Implements Command::parse() -.
 
void lua_cleanup (void)
 Clean up Lua.
 

Variables

lua_State * LuaState
 Global Lua State.
 
const struct Command LuaCommands []
 List of NeoMutt commands to register.
 

Detailed Description

Lua Commands.

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

Macro Definition Documentation

◆ LUA_COMPAT_ALL

#define LUA_COMPAT_ALL

Definition at line 30 of file commands.c.

◆ LUA_COMPAT_5_1

#define LUA_COMPAT_5_1

Definition at line 33 of file commands.c.

Function Documentation

◆ lua_init_state()

bool lua_init_state ( lua_State ** l)

Initialise a Lua State.

Parameters
[out]lLua State
Return values
trueSuccessful

Definition at line 446 of file lua.c.

447{
448 if (!l)
449 return false;
450 if (*l)
451 return true;
452
453 mutt_debug(LL_DEBUG2, "enter\n");
454 *l = luaL_newstate();
455
456 if (!*l)
457 {
458 mutt_error(_("Error: Couldn't load the lua interpreter"));
459 return false;
460 }
461
462 lua_atpanic(*l, lua_handle_panic);
463
464 /* load various Lua libraries */
465 luaL_openlibs(*l);
466 lua_expose_mutt(*l);
467
468 return true;
469}
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
static void lua_expose_mutt(lua_State *l)
Expose a 'Mutt' object to the Lua interpreter.
Definition lua.c:427
static int lua_handle_panic(lua_State *l)
Handle a panic in the Lua interpreter.
Definition lua.c:63
#define _(a)
Definition message.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lua_cleanup()

void lua_cleanup ( void )

Clean up Lua.

Definition at line 164 of file commands.c.

165{
166 if (LuaState)
167 {
168 lua_close(LuaState);
169 LuaState = NULL;
170 }
171}
lua_State * LuaState
Global Lua State.
Definition lua.c:56
+ Here is the caller graph for this function:

Variable Documentation

◆ LuaState

lua_State* LuaState
extern

Global Lua State.

Definition at line 56 of file lua.c.

◆ LuaCommands

const struct Command LuaCommands[]
Initial value:
= {
{ "lua", CMD_LUA, parse_lua,
N_("Run a Lua expression or call a Lua function"),
N_("lua <lua-command>"),
"optionalfeatures.html#lua" },
{ "lua-source", CMD_LUA_SOURCE, parse_lua_source,
N_("Execute a Lua script file"),
N_("lua-source <filename>"),
"optionalfeatures.html#lua" },
{ NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NO_FLAGS },
}
#define CF_NO_FLAGS
No flags are set.
Definition command.h:48
@ CMD_LUA_SOURCE
:lua-source
Definition command.h:89
@ CMD_LUA
:lua
Definition command.h:88
@ CMD_NONE
No Command.
Definition command.h:59
enum CommandResult parse_lua_source(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'lua-source' command - Implements Command::parse() -.
Definition commands.c:97
enum CommandResult parse_lua(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'lua' command - Implements Command::parse() -.
Definition commands.c:57
#define N_(a)
Definition message.h:32

List of NeoMutt commands to register.

Definition at line 146 of file commands.c.

146 {
147 // clang-format off
148 { "lua", CMD_LUA, parse_lua,
149 N_("Run a Lua expression or call a Lua function"),
150 N_("lua <lua-command>"),
151 "optionalfeatures.html#lua" },
152 { "lua-source", CMD_LUA_SOURCE, parse_lua_source,
153 N_("Execute a Lua script file"),
154 N_("lua-source <filename>"),
155 "optionalfeatures.html#lua" },
156
157 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NO_FLAGS },
158 // clang-format on
159};