NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
module.c File Reference

Definition of the Lua Module. More...

#include "config.h"
#include <lua.h>
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "module_data.h"
+ Include dependency graph for module.c:

Go to the source code of this file.

Functions

static bool lua_init (struct NeoMutt *n)
 Initialise a Module - Implements Module::init()
 
static bool lua_commands_register (struct NeoMutt *n, struct CommandArray *ca)
 Register NeoMutt Commands - Implements Module::commands_register()
 
static bool lua_cleanup (struct NeoMutt *n, void *data)
 Clean up a Module - Implements Module::cleanup()
 

Variables

const struct Command LuaCommands []
 List of NeoMutt commands to register.
 
const struct Module ModuleLua
 Module for the Lua library.
 

Detailed Description

Definition of the Lua Module.

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

Function Documentation

◆ lua_init()

static bool lua_init ( struct NeoMutt * n)
static

Initialise a Module - Implements Module::init()

Definition at line 42 of file module.c.

43{
44 struct LuaModuleData *mod_data = MUTT_MEM_CALLOC(1, struct LuaModuleData);
46
47 mod_data->notify = notify_new();
48 notify_set_parent(mod_data->notify, n->notify);
49
50 return true;
51}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MODULE_ID_LUA
ModuleLua, Integrated Lua scripting
Definition module_api.h:74
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
void neomutt_set_module_data(struct NeoMutt *n, enum ModuleId id, void *data)
Set the private data for a Module.
Definition neomutt.c:677
Lua private Module data.
Definition module_data.h:35
struct Notify * notify
Notifications.
Definition module_data.h:36
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
+ Here is the call graph for this function:

◆ lua_commands_register()

static bool lua_commands_register ( struct NeoMutt * n,
struct CommandArray * ca )
static

Register NeoMutt Commands - Implements Module::commands_register()

Definition at line 56 of file module.c.

57{
59}
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition command.c:51
const struct Command LuaCommands[]
List of NeoMutt commands to register.
Definition commands.c:151
+ Here is the call graph for this function:

◆ lua_cleanup()

static bool lua_cleanup ( struct NeoMutt * n,
void * data )
static

Clean up a Module - Implements Module::cleanup()

Definition at line 64 of file module.c.

65{
66 struct LuaModuleData *mod_data = data;
67
68 notify_free(&mod_data->notify);
69
70 lua_State *lua_state = mod_data->lua_state;
71 if (lua_state)
72 {
73 lua_close(lua_state);
74 mod_data->lua_state = NULL;
75 }
76
77 FREE(&mod_data);
78 return true;
79}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
lua_State * lua_state
Lua State.
Definition module_data.h:37
+ Here is the call graph for this function:

Variable Documentation

◆ LuaCommands

const struct Command LuaCommands[]
extern

List of NeoMutt commands to register.

Definition at line 151 of file commands.c.

151 {
152 // clang-format off
153 { "lua", CMD_LUA, parse_lua,
154 N_("Run a Lua expression or call a Lua function"),
155 N_("lua <lua-command>"),
156 "optionalfeatures.html#lua" },
157 { "lua-source", CMD_LUA_SOURCE, parse_lua_source,
158 N_("Execute a Lua script file"),
159 N_("lua-source <filename>"),
160 "optionalfeatures.html#lua" },
161
162 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NONE },
163 // clang-format on
164};
@ CF_NONE
No flags are set.
Definition command.h:49
@ CMD_LUA_SOURCE
:lua-source
Definition command.h:92
@ CMD_LUA
:lua
Definition command.h:91
@ CMD_NONE
No Command.
Definition command.h:62
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:99
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:56
#define N_(a)
Definition message.h:32

◆ ModuleLua

const struct Module ModuleLua
Initial value:
= {
"lua",
NULL,
NULL,
NULL,
NULL,
}
static bool lua_cleanup(struct NeoMutt *n, void *data)
Clean up a Module - Implements Module::cleanup()
Definition module.c:64
static bool lua_init(struct NeoMutt *n)
Initialise a Module - Implements Module::init()
Definition module.c:42
static bool lua_commands_register(struct NeoMutt *n, struct CommandArray *ca)
Register NeoMutt Commands - Implements Module::commands_register()
Definition module.c:56

Module for the Lua library.

Definition at line 84 of file module.c.

84 {
86 "lua",
88 NULL, // config_define_types
89 NULL, // config_define_variables
91 NULL, // gui_init
92 NULL, // gui_cleanup
94};