NeoMutt  2025-09-05-70-gcfdde0
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 <lualib.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "lib.h"
#include "parse/lib.h"
#include "muttlib.h"
#include "version.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.
 
static enum CommandResult parse_lua (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua' command - Implements Command::parse() -.
 
static enum CommandResult parse_lua_source (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua-source' command - Implements Command::parse() -.
 
void lua_init (void)
 Setup feature commands.
 
void lua_cleanup (void)
 Clean up Lua.
 

Variables

lua_State * LuaState
 Global Lua State.
 
static 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 437 of file lua.c.

438{
439 if (!l)
440 return false;
441 if (*l)
442 return true;
443
444 mutt_debug(LL_DEBUG2, "enter\n");
445 *l = luaL_newstate();
446
447 if (!*l)
448 {
449 mutt_error(_("Error: Couldn't load the lua interpreter"));
450 return false;
451 }
452
453 lua_atpanic(*l, lua_handle_panic);
454
455 /* load various Lua libraries */
456 luaL_openlibs(*l);
457 lua_expose_mutt(*l);
458
459 return true;
460}
#define mutt_error(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:90
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:45
static void lua_expose_mutt(lua_State *l)
Expose a 'Mutt' object to the Lua interpreter.
Definition lua.c:418
static int lua_handle_panic(lua_State *l)
Handle a panic in the Lua interpreter.
Definition lua.c:64
#define _(a)
Definition message.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lua_init()

void lua_init ( void )

Setup feature commands.

Definition at line 128 of file commands.c.

129{
131}
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition command.c:51
static const struct Command LuaCommands[]
List of NeoMutt commands to register.
Definition commands.c:117
Container for Accounts, Notifications.
Definition neomutt.h:42
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:50
+ 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 136 of file commands.c.

137{
138 if (LuaState)
139 {
140 lua_close(LuaState);
141 LuaState = NULL;
142 }
143}
lua_State * LuaState
Global Lua State.
Definition lua.c:57
+ Here is the caller graph for this function:

Variable Documentation

◆ LuaState

lua_State* LuaState
extern

Global Lua State.

Definition at line 57 of file lua.c.

◆ LuaCommands

const struct Command LuaCommands[]
static
Initial value:
= {
{ "lua", parse_lua, 0 },
{ "lua-source", parse_lua_source, 0 },
{ NULL, NULL, 0 },
}
static enum CommandResult parse_lua_source(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'lua-source' command - Implements Command::parse() -.
Definition commands.c:80
static enum CommandResult parse_lua(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'lua' command - Implements Command::parse() -.
Definition commands.c:58

List of NeoMutt commands to register.

Definition at line 117 of file commands.c.

117 {
118 // clang-format off
119 { "lua", parse_lua, 0 },
120 { "lua-source", parse_lua_source, 0 },
121 { NULL, NULL, 0 },
122 // clang-format on
123};