43 #include <mcabber/main.h> // mcabber_version |
43 #include <mcabber/main.h> // mcabber_version |
44 |
44 |
45 #include "config.h" |
45 #include "config.h" |
46 #include "util.h" |
46 #include "util.h" |
47 |
47 |
48 // module description |
48 // |
|
49 // options |
|
50 // |
|
51 |
|
52 #define OPT_MLUA_RC "lua_init_filename" |
|
53 #define OPT_MLUA_LM_DEBUG "lua_lm_debug" |
|
54 |
|
55 // |
|
56 // module description |
|
57 // |
|
58 |
49 void mlua_init (void); |
59 void mlua_init (void); |
50 void mlua_uninit (void); |
60 void mlua_uninit (void); |
51 |
61 |
52 #ifdef LLM_LOG_HANDLER |
62 #ifdef LLM_LOG_HANDLER |
53 #define DESCRIPTION ( \ |
63 #define DESCRIPTION ( \ |
54 "Lua scripting interface\n" \ |
64 "Lua scripting interface\n" \ |
55 "Recognizes options lua_init_file, lua_hook_function and lua_lm_debug\n" \ |
65 "Options: " OPT_MLUA_RC ", " OPT_MLUA_LM_DEBUG "\n" \ |
56 "Provides command /lua" ) |
66 "Command: /lua" ) |
57 #else |
67 #else |
58 #define DESCRIPTION ( \ |
68 #define DESCRIPTION ( \ |
59 "Lua scripting interface\n" \ |
69 "Lua scripting interface\n" \ |
60 "Recognizes options lua_init_file and lua_hook_function\n" \ |
70 "Options: " OPT_MLUA_RC "\n" \ |
61 "Provides command /lua" ) |
71 "Command: /lua" ) |
62 #endif |
72 #endif |
63 |
73 |
64 static module_info_t info_lua_experimental = { |
74 static module_info_t info_lua_dev = { |
65 .branch = "experimental", |
75 .branch = "dev", |
66 .api = 34, |
76 .api = 23, |
67 .version = PROJECT_VERSION, |
77 .version = PROJECT_VERSION, |
68 .description = DESCRIPTION, |
78 .description = DESCRIPTION, |
69 .requires = NULL, |
79 .requires = NULL, |
70 .init = mlua_init, |
80 .init = mlua_init, |
71 .uninit = mlua_uninit, |
81 .uninit = mlua_uninit, |
72 .next = NULL, |
82 .next = NULL, |
73 }; |
83 }; |
74 |
84 |
75 static module_info_t info_lua_dev = { |
85 static module_info_t info_lua_0_10_0 = { |
76 .branch = "dev", |
|
77 .api = 20, |
|
78 .version = PROJECT_VERSION, |
|
79 .description = DESCRIPTION, |
|
80 .requires = NULL, |
|
81 .init = mlua_init, |
|
82 .uninit = mlua_uninit, |
|
83 .next = &info_lua_experimental, |
|
84 }; |
|
85 |
|
86 module_info_t info_lua_0_10_0 = { |
|
87 .branch = "0.10.0", |
86 .branch = "0.10.0", |
88 .api = 1, |
87 .api = 1, |
89 .version = PROJECT_VERSION, |
88 .version = PROJECT_VERSION, |
90 .description = DESCRIPTION, |
89 .description = DESCRIPTION, |
91 .requires = NULL, |
90 .requires = NULL, |
103 .init = mlua_init, |
102 .init = mlua_init, |
104 .uninit = mlua_uninit, |
103 .uninit = mlua_uninit, |
105 .next = &info_lua_0_10_0, |
104 .next = &info_lua_0_10_0, |
106 }; |
105 }; |
107 |
106 |
|
107 // |
|
108 // globals |
|
109 // |
|
110 |
108 #ifdef MCABBER_API_HAVE_CMD_ID |
111 #ifdef MCABBER_API_HAVE_CMD_ID |
109 static gpointer lua_cmdid; |
112 static gpointer lua_cmdid; |
110 #endif |
113 #endif |
111 |
114 |
112 // global lua state object, necessary for uninitialization function |
115 // global lua state object, necessary for uninitialization function |
113 static lua_State *lua = NULL; |
116 static lua_State *lua = NULL; |
|
117 |
|
118 // |
|
119 // code |
|
120 // |
114 |
121 |
115 // caller sould g_free result |
122 // caller sould g_free result |
116 static char *mcabber_config_filename (const char *file) |
123 static char *mcabber_config_filename (const char *file) |
117 { |
124 { |
118 const char *home = getenv ("HOME"); |
125 const char *home = getenv ("HOME"); |
1603 // FIXME: this should not be here |
1610 // FIXME: this should not be here |
1604 guint lua_lm_log_handler_id; |
1611 guint lua_lm_log_handler_id; |
1605 |
1612 |
1606 void lua_lm_log_handler (const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer ignore) |
1613 void lua_lm_log_handler (const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer ignore) |
1607 { |
1614 { |
1608 if (settings_opt_get_int ("lua_lm_debug")) |
1615 if (settings_opt_get_int (OPT_MLUA_LM_DEBUG)) |
1609 scr_log_print (LPRINT_LOGNORM, "%s: %s", domain, message); |
1616 scr_log_print (LPRINT_LOGNORM, "%s: %s", domain, message); |
1610 } |
1617 } |
1611 #endif |
1618 #endif |
1612 |
1619 |
1613 static void do_lua(char *arg, lua_State *L) |
1620 static void do_lua(char *arg, lua_State *L) |
1747 lua_hook_init (lua); |
1754 lua_hook_init (lua); |
1748 lua_command_init (lua); |
1755 lua_command_init (lua); |
1749 lua_guard_init (lua); |
1756 lua_guard_init (lua); |
1750 |
1757 |
1751 { |
1758 { |
1752 char *initfile = expand_filename (settings_opt_get ("lua_init_filename")); |
1759 char *initfile = expand_filename (settings_opt_get (OPT_MLUA_RC)); |
1753 |
1760 |
1754 if (!initfile) |
1761 if (!initfile) |
1755 scr_log_print (LPRINT_LOGNORM, "lua: Cannot determine config file name"); |
1762 scr_log_print (LPRINT_LOGNORM, "lua: Cannot determine config file name"); |
1756 else { |
1763 else { |
1757 if (luaL_loadfile(lua, initfile)) { |
1764 if (luaL_loadfile(lua, initfile)) { |