NeoMutt  2025-12-11-435-g4ac674
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 440 of file lua.c.

441{
442 if (!l)
443 return false;
444 if (*l)
445 return true;
446
447 mutt_debug(LL_DEBUG2, "enter\n");
448 *l = luaL_newstate();
449
450 if (!*l)
451 {
452 mutt_error(_("Error: Couldn't load the lua interpreter"));
453 return false;
454 }
455
456 lua_atpanic(*l, lua_handle_panic);
457
458 /* load various Lua libraries */
459 luaL_openlibs(*l);
460 lua_expose_mutt(*l);
461
462 return true;
463}
#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:421
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 167 of file commands.c.

168{
169 if (LuaState)
170 {
171 lua_close(LuaState);
172 LuaState = NULL;
173 }
174}
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:100
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 149 of file commands.c.

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