author | Myhailo Danylenko <isbear@ukrpost.net> |
Wed, 31 Mar 2010 00:28:04 +0300 | |
changeset 98 | 59aeae623ac6 |
parent 97 | b00f9ce82016 |
child 102 | f3d9d9e67ee4 |
permissions | -rw-r--r-- |
72 | 1 |
|
2 |
/* Copyright 2009 Myhailo Danylenko |
|
3 |
||
4 |
This file is part of mcabber-lua. |
|
5 |
||
6 |
mcabber-lua is free software: you can redistribute it and/or modify |
|
7 |
it under the terms of the GNU General Public License as published by |
|
8 |
the Free Software Foundation, either version 2 of the License, or |
|
9 |
(at your option) any later version. |
|
10 |
||
11 |
This program is distributed in the hope that it will be useful, |
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
GNU General Public License for more details. |
|
15 |
||
16 |
You should have received a copy of the GNU General Public License |
|
17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
|
0 | 18 |
|
19 |
#include <glib.h> |
|
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
20 |
#include <gmodule.h> // g_module_* |
0 | 21 |
#include <lua.h> |
22 |
#include <lauxlib.h> |
|
23 |
#include <lualib.h> |
|
1 | 24 |
#include <stdio.h> |
25 |
#include <stdlib.h> // getenv |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
26 |
#include <string.h> // strcmp |
0 | 27 |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
28 |
#include <mcabber/logprint.h> // scr_log_print |
88
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
29 |
#include <mcabber/screen.h> // scr_Beep, scr_WriteIncomingMessage |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
30 |
#include <mcabber/hbuf.h> // HBB_PREFIX_INFO |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
31 |
#include <mcabber/commands.h> // process_command, cmd_add, cmd_del |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
32 |
#include <mcabber/xmpp.h> // xmpp_getstatus, xmpp_getstatusmsg, lconnection |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
33 |
#include <mcabber/xmpp_helper.h> // xmpp_add_feature, xmpp_del_feature |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
34 |
#include <mcabber/roster.h> // imstatus2char, foreach_buddy, buddy_*, current_buddy, BUDDATA, ROSTER_TYPE_* |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
35 |
#include <mcabber/utils.h> // from_utf8, jidtodisp |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
36 |
#include <mcabber/hooks.h> // hk_add_handler, hk_del_handler |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
37 |
#include <mcabber/settings.h> // settings_set, settings_del, settings_get |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
38 |
#include <mcabber/compl.h> // compl_new_category, compl_add_category_word, compl_del_category_word |
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
39 |
#include <mcabber/events.h> // evs_* |
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
40 |
#include <mcabber/modules.h> // module_info_t |
88
9b5c2357fad7
Change mcabber headers naming scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
83
diff
changeset
|
41 |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
42 |
#include "config.h" |
1 | 43 |
#include "util.h" |
0 | 44 |
|
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
45 |
// module description |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
46 |
static void mlua_init (void); |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
47 |
static void mlua_uninit (void); |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
48 |
|
95
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
49 |
#ifdef LLM_LOG_HANDLER |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
50 |
#define DESCRIPTION ( \ |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
51 |
"Lua scripting interface\n" \ |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
52 |
"Recognizes options lua_init_file, lua_hook_function and lua_lm_debug\n" \ |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
53 |
"Provides command /lua" ) |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
54 |
#else |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
55 |
#define DESCRIPTION ( \ |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
56 |
"Lua scripting interface\n" \ |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
57 |
"Recognizes options lua_init_file and lua_hook_function\n" \ |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
58 |
"Provides command /lua" ) |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
59 |
#endif |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
60 |
|
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
61 |
static module_info_t info_lua_experimental = { |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
62 |
.branch = "experimental", |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
63 |
.api = 10, |
95
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
64 |
.version = PROJECT_VERSION, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
65 |
.description = DESCRIPTION, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
66 |
.requires = NULL, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
67 |
.init = mlua_init, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
68 |
.uninit = mlua_uninit, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
69 |
.next = NULL, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
70 |
}; |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
71 |
|
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
72 |
module_info_t info_lua = { |
95
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
73 |
.branch = "dev", |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
74 |
.api = 11, |
95
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
75 |
.version = PROJECT_VERSION, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
76 |
.description = DESCRIPTION, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
77 |
.requires = NULL, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
78 |
.init = mlua_init, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
79 |
.uninit = mlua_uninit, |
f2f4c7810a72
Use new module struct with api version
Myhailo Danylenko <isbear@ukrpost.net>
parents:
94
diff
changeset
|
80 |
.next = &info_lua_experimental, |
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
81 |
}; |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
82 |
|
1 | 83 |
// global lua state object, necessary for uninitialization function |
84 |
static lua_State *lua = NULL; |
|
0 | 85 |
|
1 | 86 |
// caller sould g_free result |
18
ba74a9aadaf4
Fix namespace for config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
17
diff
changeset
|
87 |
static char *mcabber_config_filename (const char *file) |
0 | 88 |
{ |
1 | 89 |
const char *home = getenv ("HOME"); |
90 |
if (!home) |
|
91 |
return NULL; |
|
92 |
return g_strconcat (home, "/.mcabber/", file ? file : "", NULL); |
|
0 | 93 |
} |
94 |
||
95 |
/// print |
|
1 | 96 |
/// Prints its arguments to log with default priority. |
72 | 97 |
/// A: something, ... |
0 | 98 |
static int lua_global_print (lua_State *L) |
99 |
{ |
|
72 | 100 |
int top = lua_gettop (L); |
101 |
int i; |
|
102 |
luaL_Buffer B; |
|
103 |
luaL_buffinit (L, &B); |
|
104 |
for (i = 1; i <= top; i++) { |
|
105 |
int type = lua_type (L, i); |
|
106 |
if (i > 1) |
|
107 |
luaL_addchar (&B, '\t'); |
|
108 |
if (type == LUA_TSTRING) { |
|
109 |
size_t len; |
|
110 |
const char *str = lua_tolstring (L, i, &len); |
|
111 |
luaL_addlstring (&B, str, len); |
|
112 |
} else if (type == LUA_TNUMBER) |
|
113 |
luaL_addstring (&B, lua_tostring (L, i)); // XXX: modifies |
|
114 |
else if (type == LUA_TBOOLEAN) { |
|
115 |
if (lua_toboolean (L, i)) |
|
116 |
luaL_addstring (&B, "true"); |
|
117 |
else |
|
118 |
luaL_addstring (&B, "false"); |
|
119 |
} else if (type == LUA_TNIL) |
|
120 |
luaL_addstring (&B, "nil"); |
|
121 |
else { |
|
122 |
char xbuf[9]; |
|
123 |
luaL_addstring (&B, luaL_typename (L, i)); |
|
124 |
luaL_addstring (&B, ": 0x"); |
|
125 |
snprintf (&xbuf[0], 9, "%08x", (int) lua_topointer (L, i)); |
|
126 |
luaL_addlstring (&B, xbuf, 8); // XXX |
|
127 |
} |
|
128 |
} |
|
129 |
luaL_pushresult (&B); |
|
130 |
||
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
131 |
scr_log_print (LPRINT_LOGNORM | LPRINT_NOTUTF8, lua_tostring (L, -1)); |
1 | 132 |
return 0; |
0 | 133 |
} |
134 |
||
135 |
/// dopath |
|
136 |
/// Loads lua file from default location. |
|
13 | 137 |
/// XXX: g_filename_from_utf8? |
0 | 138 |
/// A: string (filename, without ".lua") |
6 | 139 |
/// R: string (error message, optional) |
0 | 140 |
static int lua_global_dopath (lua_State *L) |
141 |
{ |
|
1 | 142 |
const char *name = luaL_checkstring (L, 1); |
143 |
size_t size = lua_objlen (L, 1); |
|
144 |
char *path; |
|
6 | 145 |
int ret = 0; |
33 | 146 |
if (size > 4 && !strncmp (name + size - 4, ".lua", 4)) |
1 | 147 |
path = mcabber_config_filename (name); |
148 |
else { |
|
149 |
char *fname = g_strconcat (name, ".lua", NULL); |
|
150 |
path = mcabber_config_filename (fname); |
|
151 |
g_free (fname); |
|
152 |
} |
|
153 |
||
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
154 |
if ((ret = luaL_loadfile (L, path))) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
155 |
scr_log_print (LPRINT_LOGNORM, "lua: Unable to compile file %s: %s", path, lua_tostring (L, -1)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
156 |
else if ((ret = lua_pcall (L, 0, LUA_MULTRET, 0))) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
157 |
scr_log_print (LPRINT_LOGNORM, "lua: Runtime error in file %s: %s", path, lua_tostring (L, -1)); |
6 | 158 |
g_free (path); |
1 | 159 |
|
6 | 160 |
if (ret) |
161 |
return 1; |
|
162 |
else |
|
163 |
return 0; |
|
0 | 164 |
} |
165 |
||
31
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
166 |
/// yes or no ansvers |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
167 |
/// G: |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
168 |
static const string2enum_t lua_yesno[] = { |
39 | 169 |
{ "1", 1 }, |
170 |
{ "0", 0 }, |
|
31
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
171 |
{ "enable", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
172 |
{ "disable", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
173 |
{ "true", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
174 |
{ "false", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
175 |
{ "on", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
176 |
{ "off", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
177 |
{ "yes", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
178 |
{ "no", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
179 |
{ NULL, -1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
180 |
}; |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
181 |
|
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
182 |
/// main.yesno |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
183 |
/// According to yes or no ansvers returns true or false. |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
184 |
/// If ansver is not recognized, returns nil. |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
185 |
/// A: anything (string expected) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
186 |
/// R: boolean or nil |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
187 |
static int lua_main_yesno (lua_State *L) |
0 | 188 |
{ |
31
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
189 |
int type = lua_type (L, 1); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
190 |
if (type == LUA_TSTRING) { |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
191 |
int ret = luaL_checkenum (L, 1, lua_yesno); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
192 |
if (ret == -1) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
193 |
lua_pushnil (L); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
194 |
else |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
195 |
lua_pushboolean (L, ret); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
196 |
} else if (type == LUA_TNUMBER) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
197 |
lua_pushboolean (L, lua_tointeger (L, 1)); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
198 |
else if (type != LUA_TBOOLEAN) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
199 |
lua_pushnil (L); |
1 | 200 |
return 1; |
0 | 201 |
} |
202 |
||
203 |
/// log print type |
|
1 | 204 |
/// G: |
0 | 205 |
static const string2enum_t lua_lprint[] = { |
1 | 206 |
{ "normal", LPRINT_NORMAL }, |
207 |
{ "log", LPRINT_LOG }, |
|
208 |
{ "debug", LPRINT_DEBUG }, |
|
209 |
{ "notutf0", LPRINT_NOTUTF8 }, |
|
210 |
{ NULL, 0 }, |
|
0 | 211 |
}; |
212 |
||
1 | 213 |
/// roster type |
214 |
/// G: |
|
0 | 215 |
static const string2enum_t lua_roster_type[] = { |
1 | 216 |
{ "user", ROSTER_TYPE_USER }, |
217 |
{ "group", ROSTER_TYPE_GROUP }, |
|
218 |
{ "agent", ROSTER_TYPE_AGENT }, |
|
219 |
{ "room", ROSTER_TYPE_ROOM }, |
|
220 |
{ "special", ROSTER_TYPE_SPECIAL }, |
|
221 |
{ NULL, 0 }, |
|
0 | 222 |
}; |
223 |
||
224 |
/// main.log |
|
225 |
/// Prints message to log. |
|
13 | 226 |
/// Note: most likely you need notutf8 flag enabled. |
0 | 227 |
/// A: log print type, message, message... |
228 |
static int lua_main_log (lua_State *L) |
|
229 |
{ |
|
1 | 230 |
int type = luaL_checkenum_multi (L, 1, lua_lprint); |
231 |
lua_concat (L, lua_gettop (L) - 1); |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
232 |
scr_log_print (type, lua_tostring (L, -1)); |
1 | 233 |
return 0; |
0 | 234 |
} |
235 |
||
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
236 |
// expects table on top |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
237 |
static void lua_options_callback (char *key, char *value, lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
238 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
239 |
char *loc = from_utf8 (key); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
240 |
lua_pushstring (L, loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
241 |
g_free (loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
242 |
loc = from_utf8 (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
243 |
lua_pushstring (L, loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
244 |
g_free (loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
245 |
lua_settable (L, -3); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
246 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
247 |
|
0 | 248 |
/// main.option |
249 |
/// Sets or gets value of mcabber option. |
|
250 |
/// You can specify nil as a value to delete option. |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
251 |
/// If you omit option name, it returns hash table of all options. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
252 |
/// A: string (option name, optional), string (value, optional) |
0 | 253 |
/// R: string (value, optional) |
254 |
static int lua_main_option (lua_State *L) |
|
255 |
{ |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
256 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
257 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
258 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
259 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
260 |
if (lua_type (L, 2) == LUA_TNIL) // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
261 |
settings_del (SETTINGS_TYPE_OPTION, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
262 |
else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
263 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
264 |
settings_set (SETTINGS_TYPE_OPTION, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
265 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
266 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
267 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
268 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
269 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
270 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_OPTION, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
271 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
272 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
273 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
274 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
275 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
276 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
277 |
return 1; |
1 | 278 |
} |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
279 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
280 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
281 |
settings_foreach (SETTINGS_TYPE_OPTION, (void (*)(char *key, char *val, void *ud)) lua_options_callback, L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
282 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
283 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
284 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
285 |
|
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
286 |
/// main.alias |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
287 |
/// Sets or gets alias. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
288 |
/// You can specify nil as a command to delete alias. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
289 |
/// If you omit alias name, it will return hash table of all aliases. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
290 |
/// A: string (alias name, optional), string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
291 |
/// R: string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
292 |
static int lua_main_alias (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
293 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
294 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
295 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
296 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
297 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
298 |
if (lua_type (L, 2) == LUA_TNIL) { // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
299 |
settings_del (SETTINGS_TYPE_ALIAS, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
300 |
compl_del_category_word (COMPL_CMD, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
301 |
} else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
302 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
303 |
if (!settings_get (SETTINGS_TYPE_ALIAS, name)) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
304 |
compl_add_category_word (COMPL_CMD, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
305 |
settings_set (SETTINGS_TYPE_ALIAS, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
306 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
307 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
308 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
309 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
310 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
311 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_ALIAS, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
312 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
313 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
314 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
315 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
316 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
317 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
318 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
319 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
320 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
321 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
322 |
settings_foreach (SETTINGS_TYPE_ALIAS, (void (*)(char *key, char *val, void *ud)) lua_options_callback, L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
323 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
324 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
325 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
326 |
|
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
327 |
/// main.bind |
15 | 328 |
/// Sets or gets binding. |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
329 |
/// You can specify nil as a command to unbind key. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
330 |
/// If you omit keycode, it will return hash table of all bindings. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
331 |
/// A: string (keycode, optional), string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
332 |
/// R: string (command, optional) |
15 | 333 |
static int lua_main_binding (lua_State *L) |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
334 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
335 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
336 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
337 |
// just to be sure... |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
338 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
339 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
340 |
if (lua_type (L, 2) == LUA_TNIL) // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
341 |
settings_del (SETTINGS_TYPE_BINDING, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
342 |
else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
343 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
344 |
settings_set (SETTINGS_TYPE_BINDING, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
345 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
346 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
347 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
348 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
349 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
350 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_BINDING, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
351 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
352 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
353 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
354 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
355 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
356 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
357 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
358 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
359 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
360 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
361 |
settings_foreach (SETTINGS_TYPE_BINDING, (void (*)(char *key, char *val, void *ud)) lua_options_callback, L); |
1 | 362 |
return 1; |
363 |
} |
|
0 | 364 |
} |
365 |
||
33 | 366 |
/// main.fileoption |
367 |
/// Gets option, expanding it as filename. |
|
368 |
/// A: string (option name) |
|
369 |
/// R: string (expanded option value) or nil |
|
370 |
static int lua_main_fileoption (lua_State *L) |
|
371 |
{ |
|
372 |
char *fname = expand_filename (settings_opt_get (luaL_checkstring (L, 1))); |
|
373 |
if (fname) { |
|
374 |
lua_pushstring (L, fname); |
|
375 |
g_free (fname); |
|
376 |
} else |
|
377 |
lua_pushnil (L); |
|
378 |
return 1; |
|
379 |
} |
|
380 |
||
78 | 381 |
#ifdef LLM_CONNECTION_ENABLE |
0 | 382 |
/// main.connection |
383 |
/// Returns lightuserdata of mcabber's loudmouth connection. |
|
384 |
/// This can be very useful with lua-loudmouth, and not much otherwise. |
|
98
59aeae623ac6
Allow main.connection() to fail
Myhailo Danylenko <isbear@ukrpost.net>
parents:
97
diff
changeset
|
385 |
/// R: lightuserdata or nil |
0 | 386 |
static int lua_main_connection (lua_State *L) |
387 |
{ |
|
98
59aeae623ac6
Allow main.connection() to fail
Myhailo Danylenko <isbear@ukrpost.net>
parents:
97
diff
changeset
|
388 |
if (xmpp_is_online ()) |
59aeae623ac6
Allow main.connection() to fail
Myhailo Danylenko <isbear@ukrpost.net>
parents:
97
diff
changeset
|
389 |
lua_pushlightuserdata (L, lconnection); |
59aeae623ac6
Allow main.connection() to fail
Myhailo Danylenko <isbear@ukrpost.net>
parents:
97
diff
changeset
|
390 |
else |
59aeae623ac6
Allow main.connection() to fail
Myhailo Danylenko <isbear@ukrpost.net>
parents:
97
diff
changeset
|
391 |
lua_pushnil (L); |
1 | 392 |
return 1; |
0 | 393 |
} |
78 | 394 |
#endif |
0 | 395 |
|
396 |
/// main.print_info |
|
397 |
/// Prints a system message to buddy's window. |
|
398 |
/// A: string (jid), string (message) |
|
399 |
static int lua_main_print_info (lua_State *L) |
|
400 |
{ |
|
13 | 401 |
char *jid = to_utf8 (luaL_checkstring (L, 1)); |
402 |
char *to = jidtodisp (jid); |
|
403 |
char *mesg = to_utf8 (luaL_checkstring (L, 2)); |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
404 |
scr_write_incoming_message (to, mesg, 0, HBB_PREFIX_INFO, 0); |
13 | 405 |
g_free (mesg); |
1 | 406 |
g_free (to); |
13 | 407 |
g_free (jid); |
1 | 408 |
return 0; |
0 | 409 |
} |
410 |
||
411 |
/// main.beep |
|
412 |
/// Beeps with system speaker. |
|
413 |
static int lua_main_beep (lua_State *L) |
|
414 |
{ |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
415 |
scr_beep (); |
1 | 416 |
return 0; |
0 | 417 |
} |
418 |
||
419 |
/// main.run |
|
420 |
/// Runs specified mcabber command. |
|
421 |
/// A: string |
|
422 |
static int lua_main_run (lua_State *L) |
|
423 |
{ |
|
1 | 424 |
process_command (luaL_checkstring (L, 1), TRUE); |
425 |
return 0; |
|
0 | 426 |
} |
427 |
||
428 |
/// main.status |
|
429 |
/// Returns your current status. |
|
1 | 430 |
/// R: string (status letter), string (status message) |
0 | 431 |
static int lua_main_status (lua_State *L) |
432 |
{ |
|
1 | 433 |
char *sm = from_utf8 (xmpp_getstatusmsg ()); |
434 |
lua_pushlstring (L, &imstatus2char[xmpp_getstatus ()], 1); |
|
435 |
lua_pushstring (L, sm); |
|
436 |
g_free (sm); |
|
437 |
return 2; |
|
0 | 438 |
} |
439 |
||
1 | 440 |
// expects table on top |
0 | 441 |
static void lua_rosterlist_callback (gpointer buddy, lua_State *L) |
442 |
{ |
|
13 | 443 |
char *jid = from_utf8 (buddy_getjid (buddy)); |
1 | 444 |
lua_pushnumber (L, lua_objlen (L, -1) + 1); |
13 | 445 |
lua_pushstring (L, jid); |
1 | 446 |
lua_settable (L, -3); |
13 | 447 |
g_free (jid); |
0 | 448 |
} |
449 |
||
450 |
/// main.roster |
|
451 |
/// Returns array of jids of buddies in roster. |
|
452 |
/// R: table |
|
453 |
static int lua_main_roster (lua_State *L) |
|
454 |
{ |
|
1 | 455 |
lua_newtable (L); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
456 |
foreach_buddy (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM, (void (*) (gpointer buddy, void *data)) lua_rosterlist_callback, L); |
1 | 457 |
return 1; |
0 | 458 |
} |
459 |
||
460 |
/// main.current_buddy |
|
10 | 461 |
/// Returns jid of current selected buddy or sets current buddy to buddy with specified jid. |
462 |
/// A: string (optional) |
|
463 |
/// R: string (optional) |
|
0 | 464 |
static int lua_main_current_buddy (lua_State *L) |
465 |
{ |
|
10 | 466 |
if (lua_gettop (L) > 0) { // Set |
13 | 467 |
// XXX: we need not convert to utf, RS works on jids/names in locale charset, |
468 |
// but will jidtodisp always correctly work on such tings? |
|
10 | 469 |
char *jid = jidtodisp (luaL_checkstring (L, 1)); |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
470 |
scr_roster_search (jid); |
10 | 471 |
g_free (jid); |
472 |
return 0; |
|
473 |
} else { // Get |
|
13 | 474 |
char *jid = from_utf8 (buddy_getjid (BUDDATA (current_buddy))); |
475 |
lua_pushstring (L, jid); |
|
476 |
g_free (jid); |
|
10 | 477 |
return 1; |
478 |
} |
|
479 |
} |
|
480 |
||
481 |
/// main.full_jid |
|
482 |
/// Returns full jid (with current resource) of specified buddy (or current, if not specified). |
|
483 |
/// Note, that if there are no resources online, it will return just what it got. |
|
484 |
/// A: string (jid, optional) |
|
485 |
/// R: string (jid) |
|
486 |
static int lua_main_full_jid (lua_State *L) |
|
487 |
{ |
|
40 | 488 |
GList *buddy; |
10 | 489 |
GSList *resources; |
490 |
GSList *resource; |
|
13 | 491 |
if (lua_gettop (L) > 0) { |
492 |
char *jid = from_utf8 (luaL_checkstring (L, 1)); |
|
493 |
buddy = buddy_search_jid (jid); |
|
494 |
g_free (jid); |
|
495 |
} else |
|
10 | 496 |
buddy = current_buddy; |
497 |
if (!buddy) |
|
498 |
return 0; |
|
499 |
resources = buddy_getresources (BUDDATA (buddy)); |
|
500 |
if (!resources) { |
|
13 | 501 |
char *loc = from_utf8 (buddy_getjid (BUDDATA (buddy))); |
502 |
lua_pushstring (L, loc); |
|
503 |
g_free (loc); |
|
504 |
} else { |
|
505 |
char *jid = from_utf8 (buddy_getjid (BUDDATA (buddy))); |
|
506 |
char *res = from_utf8 (g_slist_last (resources)->data); |
|
507 |
lua_pushfstring (L, "%s%c%s", jid, JID_RESOURCE_SEPARATOR, res); |
|
508 |
for (resource = resources; resource; resource = g_slist_next (resource)) |
|
509 |
g_free (resource->data); |
|
510 |
g_slist_free (resources); |
|
511 |
g_free (jid); |
|
512 |
g_free (res); |
|
10 | 513 |
} |
1 | 514 |
return 1; |
0 | 515 |
} |
516 |
||
517 |
typedef struct { |
|
1 | 518 |
lua_State *L; |
519 |
gpointer buddy; |
|
0 | 520 |
} lua_state_and_buddy_t; // :) |
521 |
||
29 | 522 |
/// resources table |
523 |
/// Hash table with resource name as keys and another hash tables as values. |
|
524 |
/// Inner tables contain resource-specific information: priority, status and message. |
|
0 | 525 |
static void lua_buddy_resources_callback (gpointer resource, lua_state_and_buddy_t *d) |
526 |
{ |
|
13 | 527 |
char *loc = from_utf8 (resource); |
528 |
lua_pushstring (d->L, loc); |
|
529 |
g_free (loc); |
|
1 | 530 |
lua_createtable (d->L, 0, 3); |
531 |
lua_pushstring (d->L, "priority"); |
|
532 |
lua_pushnumber (d->L, buddy_getresourceprio (d->buddy, resource)); |
|
533 |
lua_settable (d->L, -3); |
|
534 |
lua_pushstring (d->L, "status"); |
|
535 |
lua_pushlstring (d->L, &imstatus2char[buddy_getstatus (d->buddy, resource)], 1); |
|
536 |
lua_settable (d->L, -3); |
|
537 |
lua_pushstring (d->L, "message"); |
|
13 | 538 |
loc = from_utf8 (buddy_getstatusmsg (d->buddy, resource)); |
539 |
lua_pushstring (d->L, loc); |
|
540 |
g_free (loc); |
|
1 | 541 |
lua_settable (d->L, -3); |
542 |
lua_settable (d->L, -3); |
|
10 | 543 |
g_free (resource); |
0 | 544 |
} |
545 |
||
546 |
/// main.buddy_info |
|
547 |
/// Returns a hash table with information on specified buddy. |
|
29 | 548 |
/// Table contains fields type, name, onserver and resources (which points to resources table). |
0 | 549 |
/// A: string (jid) |
550 |
/// R: table |
|
551 |
static int lua_main_buddy_info (lua_State *L) |
|
552 |
{ |
|
13 | 553 |
char *loc = to_utf8 (luaL_checkstring (L, 1)); |
554 |
char *jid = jidtodisp (loc); |
|
1 | 555 |
GSList *buddy = roster_find (jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
10 | 556 |
GSList *resources; |
1 | 557 |
lua_state_and_buddy_t snb; |
558 |
g_free (jid); |
|
13 | 559 |
g_free (loc); |
1 | 560 |
|
561 |
if (!buddy) { |
|
562 |
lua_pushnil (L); |
|
563 |
return 1; |
|
564 |
} |
|
0 | 565 |
|
1 | 566 |
lua_createtable (L, 0, 3); |
567 |
lua_pushstring (L, "type"); |
|
568 |
luaL_pushenum (L, buddy_gettype (BUDDATA (buddy)), lua_roster_type); |
|
569 |
lua_settable (L, -3); |
|
570 |
lua_pushstring (L, "name"); |
|
13 | 571 |
loc = from_utf8 (buddy_getname (BUDDATA (buddy))); |
572 |
lua_pushstring (L, loc); |
|
573 |
g_free (loc); |
|
1 | 574 |
lua_settable (L, -3); |
575 |
lua_pushstring (L, "onserver"); |
|
576 |
lua_pushboolean (L, buddy_getonserverflag (BUDDATA (buddy))); |
|
577 |
lua_settable (L, -3); |
|
578 |
lua_pushstring (L, "resources"); |
|
579 |
lua_createtable (L, 0, 0); |
|
580 |
snb.L = L; |
|
581 |
snb.buddy = BUDDATA (buddy); |
|
10 | 582 |
resources = buddy_getresources (BUDDATA (buddy)); |
1 | 583 |
g_slist_foreach (buddy_getresources (BUDDATA (buddy)), (GFunc) lua_buddy_resources_callback, &snb); |
10 | 584 |
g_slist_free (resources); |
585 |
lua_settable (L, -3); |
|
1 | 586 |
|
587 |
return 1; |
|
0 | 588 |
} |
589 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
590 |
// XMPP DISCO FEATURES |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
591 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
592 |
GSList *lua_added_features = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
593 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
594 |
/// main.add_feature |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
595 |
/// Adds xmlns to disco#info features list. |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
596 |
/// A: string (xmlns) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
597 |
static int lua_main_add_feature (lua_State *L) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
598 |
{ |
13 | 599 |
char *xmlns = to_utf8 (luaL_checkstring (L, 1)); |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
600 |
xmpp_add_feature (xmlns); |
13 | 601 |
lua_added_features = g_slist_prepend (lua_added_features, xmlns); |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
602 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
603 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
604 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
605 |
/// main.del_feature |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
606 |
/// Removes xmlns from disco#info features list. |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
607 |
/// A: stirng (xmlns) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
608 |
static int lua_main_del_feature (lua_State *L) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
609 |
{ |
13 | 610 |
char *xmlns = to_utf8 (luaL_checkstring (L, 1)); |
611 |
GSList *el = g_slist_find_custom (lua_added_features, xmlns, (GCompareFunc) strcmp); |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
612 |
xmpp_del_feature (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
613 |
if (el) { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
614 |
g_free (el->data); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
615 |
lua_added_features = g_slist_delete_link (lua_added_features, el); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
616 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
617 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
618 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
619 |
|
52 | 620 |
// MCABBER EVENTS |
621 |
||
622 |
/// event context |
|
623 |
/// Enum, indicating what exactly caused event function firing. |
|
624 |
/// G: |
|
625 |
static const string2enum_t lua_event_context[] = { |
|
626 |
{ "timeout", EVS_CONTEXT_TIMEOUT }, |
|
627 |
{ "cancel", EVS_CONTEXT_CANCEL }, |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
628 |
{ "reject", EVS_CONTEXT_REJECT }, |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
629 |
{ "accept", EVS_CONTEXT_ACCEPT }, |
52 | 630 |
{ NULL, 0 }, |
631 |
}; |
|
632 |
||
633 |
typedef struct { |
|
634 |
lua_State *L; |
|
635 |
int reference; |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
636 |
int evid; |
52 | 637 |
} lua_event_callback_t; |
638 |
||
639 |
static GSList *lua_events = NULL; |
|
640 |
||
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
641 |
static void lua_event_callback_destroy_notify (gpointer udata) |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
642 |
{ |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
643 |
lua_event_callback_t *cb = udata; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
644 |
|
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
645 |
luaL_unref (cb -> L, LUA_REGISTRYINDEX, cb->reference); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
646 |
luaL_unref (cb -> L, LUA_REGISTRYINDEX, cb->evid); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
647 |
luaL_free (cb -> L, cb); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
648 |
} |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
649 |
|
52 | 650 |
/// event function |
651 |
/// Function to be called, when some event state change occurs |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
652 |
/// A: event context, string (event args) |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
653 |
/// R: boolean (if event shoud be preserved) |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
654 |
static gboolean lua_event_callback (guint context, const gchar *arg, gpointer userdata) |
52 | 655 |
{ |
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
656 |
lua_event_callback_t *cb = userdata; |
52 | 657 |
|
658 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
|
659 |
luaL_pushenum (cb->L, context, lua_event_context); |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
660 |
lua_pushstring (cb -> L, arg); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
661 |
if (lua_pcall (cb->L, 2, 1, 0)) { |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
662 |
scr_log_print (LPRINT_LOGNORM, "lua: Event callback execution error: %s", lua_tostring (cb->L, -1)); |
52 | 663 |
lua_pop (cb->L, 1); |
664 |
} |
|
665 |
||
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
666 |
if (lua_toboolean (cb -> L, -1)) |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
667 |
return TRUE; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
668 |
else { |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
669 |
lua_events = g_slist_remove (lua_events, cb); // XXX |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
670 |
return FALSE; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
671 |
} |
52 | 672 |
} |
673 |
||
674 |
/// main.event |
|
675 |
/// Creates new event. If called without arguments, returns event id list. |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
676 |
/// A: event function (optional), string (event id), string (description, optional), integer (expiration timeout, optional) |
52 | 677 |
/// R: string (event id) or nothing (creation error) or table (list of event names) |
678 |
static int lua_main_event (lua_State *L) |
|
679 |
{ |
|
680 |
int top = lua_gettop (L); |
|
681 |
if (top > 0) { // Create |
|
682 |
lua_event_callback_t *cb; |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
683 |
const char *evid = NULL; |
52 | 684 |
int timeout = 0; |
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
685 |
const char *desc = NULL; |
52 | 686 |
luaL_argcheck (L, lua_type (L, 1) == LUA_TFUNCTION, 1, "event function expected"); |
687 |
||
688 |
if (top > 1) { |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
689 |
evid = luaL_checkstring (L, 2); |
52 | 690 |
if (top > 2) { |
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
691 |
timeout = luaL_checkinteger (L, 3); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
692 |
if (top > 2) { |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
693 |
desc = luaL_checkstring (L, 4); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
694 |
lua_pop (L, 3); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
695 |
} else |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
696 |
lua_pop (L, 2); |
52 | 697 |
} else |
698 |
lua_pop (L, 1); |
|
699 |
} |
|
700 |
||
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
701 |
lua_pushvalue (L, 1); // XXX |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
702 |
cb = luaL_malloc (L, sizeof (lua_event_callback_t)); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
703 |
cb -> L = L; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
704 |
cb -> reference = luaL_ref (L, LUA_REGISTRYINDEX); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
705 |
cb -> evid = LUA_NOREF; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
706 |
lua_events = g_slist_prepend (lua_events, cb); |
52 | 707 |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
708 |
evid = evs_new (desc, evid, timeout, lua_event_callback, cb, lua_event_callback_destroy_notify); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
709 |
if (!evid) { |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
710 |
lua_events = g_slist_remove (lua_events, cb); // XXX |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
711 |
return 0; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
712 |
} |
52 | 713 |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
714 |
lua_pushstring (L, evid); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
715 |
lua_pushvalue (L, -1); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
716 |
cb -> evid = luaL_ref (L, LUA_REGISTRYINDEX); // XXX |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
717 |
return 1; |
52 | 718 |
|
719 |
} else { // List |
|
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
720 |
GSList *events = evs_geteventslist (); |
52 | 721 |
GSList *event; |
722 |
||
723 |
lua_newtable (L); |
|
724 |
for (event = events; event; event = g_slist_next (event)) { |
|
725 |
lua_pushstring (L, event->data); |
|
726 |
luaL_ref (L, -2); |
|
727 |
} |
|
728 |
g_slist_free (events); |
|
729 |
||
730 |
return 1; |
|
731 |
} |
|
732 |
} |
|
733 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
734 |
// MCABBER COMMANDS |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
735 |
|
9 | 736 |
/// completion type |
737 |
/// Built-it completion types can be specified as string, instead of id. |
|
738 |
/// G: |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
739 |
static string2enum_t lua_completion_type[] = { // not const, we need to modify yesno |
9 | 740 |
{ "cmd", COMPL_CMD }, |
741 |
{ "jid", COMPL_JID }, |
|
742 |
{ "urljid", COMPL_URLJID }, |
|
743 |
{ "name", COMPL_NAME }, |
|
744 |
{ "status", COMPL_STATUS }, |
|
745 |
{ "filename", COMPL_FILENAME }, |
|
746 |
{ "roster", COMPL_ROSTER }, |
|
747 |
{ "buffer", COMPL_BUFFER }, |
|
748 |
{ "group", COMPL_GROUP }, |
|
749 |
{ "groupname", COMPL_GROUPNAME }, |
|
750 |
{ "multiline", COMPL_MULTILINE }, |
|
751 |
{ "room", COMPL_ROOM }, |
|
752 |
{ "resource", COMPL_RESOURCE }, |
|
753 |
{ "auth", COMPL_AUTH }, |
|
754 |
{ "request", COMPL_REQUEST }, |
|
755 |
{ "events", COMPL_EVENTS }, |
|
756 |
{ "eventsid", COMPL_EVENTSID }, |
|
757 |
{ "pgp", COMPL_PGP }, |
|
758 |
{ "color", COMPL_COLOR }, |
|
759 |
{ "otr", COMPL_OTR }, |
|
760 |
{ "ortpolicy", COMPL_OTRPOLICY }, |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
761 |
{ "yesno", 0 }, |
9 | 762 |
{ NULL, 0 }, |
763 |
}; |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
764 |
#define MLUA_YESNO_POS ( 21 ) |
9 | 765 |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
766 |
typedef struct { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
767 |
int reference; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
768 |
int parse_args; |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
769 |
lua_State *L; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
770 |
} lua_command_callback_t; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
771 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
772 |
static GSList *lua_added_commands = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
773 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
774 |
static GSList *lua_added_categories = NULL; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
775 |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
776 |
// returns true if string contains errors - unclosed quotes or unvalued option |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
777 |
/// command arguments table |
27 | 778 |
/// It can parse barewords (with escapes), double-quoted strings (with escapes), single-quoted strings (without escapes), options and arguments. |
24 | 779 |
/// Arguments are separated only by whitespace, so, consequential quoted strings or barewords are one argument. |
27 | 780 |
/// This strings are equal: |
24 | 781 |
/// * ab\ cd\'e\\f\" |
782 |
/// * "ab cd'e\\f\"" |
|
27 | 783 |
/// * 'ab cd'\''e\f"' |
784 |
/// * ab" cd'"'e\f"' |
|
785 |
/// Returned table have option names as keys, option values as values, and arguments as sequential members. -- option is supported. |
|
786 |
/// Example: "-t jid -m 9 -- -aa bb cc" will result in { t = 'jid', m = 9, '-aa', 'bb', 'cc' } |
|
787 |
/// Implementation notes: |
|
788 |
/// * All options should be before any arguments. First non-option argument disables options recognizing. |
|
789 |
/// * EOL is a cutting edge, that can cut much earlier, than you expect. Non-closed quoted strings lose leading quote and option without value loses its leading minus. |
|
790 |
/// * Escape character just before EOL is preserved. |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
791 |
static int luaL_pushargs (lua_State *L, const char *args) |
24 | 792 |
{ |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
793 |
const char *p = args; |
24 | 794 |
luaL_Buffer buf; |
27 | 795 |
int option = 0; |
796 |
int options = 1; |
|
24 | 797 |
|
798 |
lua_newtable (L); |
|
799 |
luaL_buffinit (L, &buf); |
|
800 |
while (*p) { |
|
801 |
if (*p == ' ') { |
|
802 |
++p; |
|
803 |
continue; |
|
804 |
} |
|
805 |
if (*p == '"') { // soft quote |
|
806 |
const char *start = ++p; |
|
807 |
while (*p) { |
|
808 |
if (*p == '\\') { // escape symbol |
|
809 |
luaL_addlstring (&buf, start, p - start); |
|
810 |
start = ++p; |
|
811 |
if (*p) // skip symbol |
|
812 |
++p; |
|
813 |
else // add last \ in line |
|
814 |
luaL_addchar (&buf, '\\'); |
|
815 |
} else if (*p == '"') // quotation end |
|
816 |
break; |
|
817 |
else |
|
818 |
++p; |
|
819 |
} |
|
27 | 820 |
luaL_addlstring (&buf, start, p - start); // XXX: eats quote on eol |
24 | 821 |
if (*p) |
822 |
++p; |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
823 |
else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
824 |
return 1; |
24 | 825 |
} else if (*p == '\'') { // no-escape quote |
826 |
const char *start = ++p; |
|
827 |
while (*p && *p != '\'') |
|
828 |
p++; |
|
27 | 829 |
luaL_addlstring (&buf, start, p - start); // XXX: eats quote on eol |
24 | 830 |
if (*p) |
831 |
++p; |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
832 |
else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
833 |
return 1; |
24 | 834 |
} else { // bareword |
835 |
const char *start = p; |
|
836 |
while (*p) { |
|
837 |
if (*p == '\\') { |
|
838 |
luaL_addlstring (&buf, start, p - start); |
|
839 |
start = ++p; |
|
840 |
if (*p) // skip symbol |
|
841 |
++p; |
|
842 |
else // add last \ in line |
|
843 |
luaL_addchar (&buf, '\\'); |
|
844 |
} else if (*p == ' ' || *p == '\'' || *p == '"') |
|
845 |
break; |
|
846 |
else |
|
847 |
++p; |
|
848 |
} |
|
849 |
luaL_addlstring (&buf, start, p - start); |
|
850 |
} |
|
851 |
||
852 |
if ((!*p) || *p == ' ') { |
|
27 | 853 |
const char *result; |
24 | 854 |
luaL_pushresult (&buf); |
27 | 855 |
|
856 |
result = lua_tostring (L, -1); |
|
857 |
if (options && !option && *result == '-') { // option |
|
858 |
if (*(result+1) == '-' && !*(result+2)) { // end of options |
|
859 |
lua_pop (L, 1); |
|
860 |
options = 0; |
|
861 |
} else { // option name |
|
862 |
lua_pushstring (L, result + 1); |
|
863 |
lua_remove (L, -2); |
|
864 |
option = 1; |
|
865 |
} |
|
866 |
} else if (option) { // opion value |
|
867 |
lua_settable (L, -3); |
|
868 |
option = 0; |
|
869 |
} else { // argument |
|
870 |
options = 0; |
|
871 |
luaL_ref (L, -2); |
|
872 |
} |
|
873 |
||
24 | 874 |
luaL_buffinit (L, &buf); |
875 |
} |
|
876 |
} |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
877 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
878 |
if (option) { |
27 | 879 |
luaL_ref (L, -2); // XXX: eats minus on eol |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
880 |
return 1; |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
881 |
} |
27 | 882 |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
883 |
return 0; |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
884 |
} |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
885 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
886 |
/// command function |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
887 |
/// Function to handle newly registered command. |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
888 |
/// Argument type passed depends on how command is registered. |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
889 |
/// A: string (arguments) or command arguments table |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
890 |
static void lua_main_command_handler (char *args, lua_command_callback_t *cb) |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
891 |
{ |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
892 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
893 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
894 |
if (cb->parse_args) |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
895 |
luaL_pushargs (cb->L, args); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
896 |
else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
897 |
lua_pushstring (cb->L, args); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
898 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
899 |
if (lua_pcall (cb->L, 1, 0, 0)) { |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
900 |
scr_log_print (LPRINT_LOGNORM, "lua: Command execution error: %s", lua_tostring (cb->L, -1)); |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
901 |
lua_pop (cb->L, 1); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
902 |
} |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
903 |
} |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
904 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
905 |
/// main.parse_args |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
906 |
/// Function to parse command argument string to command arguments table. |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
907 |
/// A: string |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
908 |
/// R: table |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
909 |
static int lua_main_parse_args (lua_State *L) |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
910 |
{ |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
911 |
luaL_pushargs (L, luaL_checkstring (L, 1)); |
24 | 912 |
return 1; |
913 |
} |
|
914 |
||
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
915 |
/// main.add_category |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
916 |
/// Adds completion category. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
917 |
/// A: table (values are used as words for completion, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
918 |
/// R: integer (category id, in fact completion type) or nil |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
919 |
static int lua_main_add_category (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
920 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
921 |
guint cid; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
922 |
|
15 | 923 |
if (lua_gettop (L) > 0) { |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
924 |
luaL_argcheck (L, lua_type (L, 1) == LUA_TTABLE, 1, "table expected"); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
925 |
cid = compl_new_category (); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
926 |
if (cid) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
927 |
lua_pushnil (L); |
17
3a12759a22b1
Fix segfault in add_category
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
928 |
while (lua_next (L, 1)) { |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
929 |
char *word = to_utf8 (luaL_checkstring (L, -1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
930 |
if (word) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
931 |
compl_add_category_word (cid, word); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
932 |
g_free (word); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
933 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
934 |
lua_pop (L, 1); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
935 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
936 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
937 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
938 |
cid = compl_new_category (); |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
939 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
940 |
if (cid) { |
15 | 941 |
lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) cid); |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
942 |
lua_pushinteger (L, cid); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
943 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
944 |
lua_pushnil (L); |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
945 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
946 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
947 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
948 |
|
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
949 |
/// main.del_category |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
950 |
/// Removes completion category. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
951 |
/// A: integer (category id) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
952 |
static int lua_main_del_category (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
953 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
954 |
guint cid = luaL_checkinteger (L, 1); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
955 |
compl_del_category (cid); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
956 |
lua_added_categories = g_slist_remove (lua_added_categories, (gpointer) cid); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
957 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
958 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
959 |
|
8 | 960 |
/// main.add_completion |
961 |
/// Adds word to a completion list. |
|
962 |
/// A: integer (completion group id), string (word) |
|
963 |
static int lua_main_add_completion (lua_State *L) |
|
964 |
{ |
|
13 | 965 |
guint cid = luaL_checkinteger (L, 1); |
966 |
char *word = to_utf8 (luaL_checkstring (L, 2)); // XXX |
|
8 | 967 |
compl_add_category_word (cid, word); |
13 | 968 |
g_free (word); |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
969 |
return 0; |
8 | 970 |
} |
971 |
||
972 |
/// main.del_completion |
|
973 |
/// Removes word from a completion list. |
|
974 |
/// A: integer (completion group id), string (word) |
|
975 |
static int lua_main_del_completion (lua_State *L) |
|
976 |
{ |
|
13 | 977 |
guint cid = luaL_checkinteger (L, 1); |
978 |
char *word = to_utf8 (luaL_checkstring (L, 2)); // XXX |
|
8 | 979 |
compl_del_category_word (cid, word); |
13 | 980 |
g_free (word); |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
981 |
return 0; |
8 | 982 |
} |
983 |
||
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
984 |
/// main.command |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
985 |
/// Associates or breaks association between mcabber command name and lua function. |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
986 |
/// To unregister command omit function argument. |
8 | 987 |
/// If you specify a third argument, table (even empty), function will return completion group id or nothing. |
9 | 988 |
/// You can also specify a string name (see completion type) instead of table, for non-builtin, you can just pass integer id. |
8 | 989 |
/// Note, that for now there are no way to unregister completion group, so, resources can be exausted easily. |
990 |
/// Also note, that it ignores keys in a completion table. |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
991 |
/// A: string (command name), command function (optional), boolean (parse args flag, optional), table (completions, optional)/completion type (or integer comletion group id, optional) |
9 | 992 |
/// R: completion type (integer completion group id or string for builtin types, optional) |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
993 |
static int lua_main_command (lua_State *L) |
39 | 994 |
{ |
13 | 995 |
const char *name = luaL_checkstring (L, 1); // XXX: to_utf8? looks like no :/ |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
996 |
lua_command_callback_t *cb; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
997 |
int top = lua_gettop (L); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
998 |
if (top > 1) { // Register |
8 | 999 |
guint cid = 0; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1000 |
int parse = 0; |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1001 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1002 |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1003 |
if (top > 2) { // parse flag provided |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1004 |
parse = lua_toboolean (L, 3); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1005 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1006 |
if (top > 3) { // Completions provided |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1007 |
if (lua_type (L, 4) == LUA_TTABLE) { |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1008 |
cid = compl_new_category (); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1009 |
if (cid) { |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1010 |
lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) cid); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1011 |
lua_pushnil (L); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1012 |
while (lua_next (L, 4)) { |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1013 |
char *word = to_utf8 (luaL_checkstring (L, -1)); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1014 |
compl_add_category_word (cid, word); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1015 |
lua_pop (L, 1); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1016 |
g_free (word); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1017 |
} |
8 | 1018 |
} |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1019 |
} else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1020 |
cid = luaL_checkenum (L, 4, lua_completion_type); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1021 |
} |
8 | 1022 |
} |
1023 |
||
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1024 |
cb = luaL_malloc (L, sizeof (lua_command_callback_t)); |
8 | 1025 |
lua_pushvalue (L, 2); |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1026 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1027 |
cb->parse_args = parse; |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
1028 |
cb->L = L; |
8 | 1029 |
cmd_add (name, "", cid, 0, (void (*) (char *p)) lua_main_command_handler, cb); |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1030 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1031 |
lua_added_commands = g_slist_prepend (lua_added_commands, g_strdup (name)); |
8 | 1032 |
|
1033 |
if (cid) { |
|
9 | 1034 |
luaL_pushenum (L, cid, lua_completion_type); |
8 | 1035 |
return 1; |
1036 |
} |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1037 |
} else { // Unregister |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1038 |
GSList *el = g_slist_find_custom (lua_added_commands, name, (GCompareFunc) g_strcmp0); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1039 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1040 |
cb = cmd_del (name); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1041 |
if (cb) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1042 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1043 |
luaL_free (cb->L, cb); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1044 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1045 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1046 |
if (el) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1047 |
g_free (el->data); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1048 |
lua_added_commands = g_slist_delete_link (lua_added_commands, el); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1049 |
} |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1050 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1051 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1052 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1053 |
|
0 | 1054 |
// TIMER |
1055 |
||
1056 |
typedef struct { |
|
1 | 1057 |
int reference; |
29 | 1058 |
guint source; |
1 | 1059 |
lua_State *L; |
0 | 1060 |
} lua_timer_callback_t; |
1061 |
||
29 | 1062 |
static GSList *lua_timers = NULL; |
1063 |
||
0 | 1064 |
static void lua_timer_callback_destroy (lua_timer_callback_t *cb) |
1065 |
{ |
|
1 | 1066 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
29 | 1067 |
lua_timers = g_slist_remove (lua_timers, (gpointer) cb->source); |
1 | 1068 |
luaL_free (cb->L, cb); |
0 | 1069 |
} |
1070 |
||
1071 |
/// timer function |
|
1072 |
/// Function, that will be called periodically until it returns false. |
|
1073 |
/// R: boolean |
|
1074 |
static gboolean lua_timer_callback (lua_timer_callback_t *cb) |
|
1075 |
{ |
|
1 | 1076 |
int ret; |
1077 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
|
1078 |
if (lua_pcall (cb->L, 0, 1, 0)) { |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1079 |
scr_log_print (LPRINT_LOGNORM, "lua: Timer callback execution error: %s", lua_tostring (cb->L, -1)); |
1 | 1080 |
lua_pop (cb->L, 1); |
1081 |
return FALSE; |
|
1082 |
} |
|
1083 |
ret = lua_toboolean (cb->L, -1); |
|
1084 |
lua_pop (cb->L, 1); |
|
1085 |
return ret; |
|
0 | 1086 |
} |
1087 |
||
1088 |
/// main.timer |
|
1089 |
/// Creates new timer function, that will be called periodically. |
|
1090 |
/// A: integer (interval, seconds), timer function |
|
1091 |
static int lua_main_timer (lua_State *L) |
|
1092 |
{ |
|
1 | 1093 |
int interval = luaL_checkint (L, 1); |
29 | 1094 |
guint source; |
1 | 1095 |
lua_timer_callback_t *cb; |
1096 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
|
0 | 1097 |
|
1 | 1098 |
cb = luaL_malloc (L, sizeof (lua_timer_callback_t)); |
1099 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
|
1100 |
cb->L = L; |
|
0 | 1101 |
|
30
2cf24aced294
Definitions moved to cmake options
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
1102 |
source = g_timeout_add_seconds_full (MLUA_SOURCE_PRIORITY, interval, (GSourceFunc) lua_timer_callback, cb, (GDestroyNotify) lua_timer_callback_destroy); |
29 | 1103 |
cb->source = source; |
1104 |
lua_timers = g_slist_prepend (lua_timers, (gpointer) source); |
|
1105 |
||
1 | 1106 |
return 0; |
0 | 1107 |
} |
1108 |
||
1109 |
// BACKGROUND PIPE READING |
|
1110 |
||
1111 |
typedef struct { |
|
1 | 1112 |
lua_State *L; |
80
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1113 |
guint source; |
1 | 1114 |
FILE *fd; |
1115 |
int reference; |
|
0 | 1116 |
} lua_bgread_callback_t; |
1117 |
||
80
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1118 |
static GSList *lua_bgreads = NULL; |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1119 |
|
30
2cf24aced294
Definitions moved to cmake options
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
1120 |
static gchar lua_bgread_buffer[MLUA_BGREAD_BUFFER]; |
0 | 1121 |
|
1122 |
static void lua_bgread_callback_destroy (lua_bgread_callback_t *cb) |
|
1123 |
{ |
|
1 | 1124 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
80
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1125 |
pclose (cb->fd); // Not necessary? |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1126 |
lua_bgreads = g_slist_remove (lua_bgreads, (gpointer) cb->source); |
1 | 1127 |
luaL_free (cb->L, cb); |
0 | 1128 |
} |
1129 |
||
1130 |
/// background reading function |
|
1131 |
/// Function, that processes output from pipe in asynchroneous way. |
|
1132 |
/// A: string (data) or nil (eof) |
|
1133 |
/// R: boolean (false if reading should be terminated) |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1134 |
static gboolean lua_bgread_callback (GIOChannel *source, GIOCondition condition, lua_bgread_callback_t *cb) |
0 | 1135 |
{ |
1 | 1136 |
int ret = TRUE; |
0 | 1137 |
|
1 | 1138 |
if (condition | G_IO_IN) { // data |
1139 |
while (TRUE) { |
|
1140 |
gsize read = 0; |
|
30
2cf24aced294
Definitions moved to cmake options
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
1141 |
g_io_channel_read_chars (source, lua_bgread_buffer, MLUA_BGREAD_BUFFER, &read, NULL); |
78 | 1142 |
if (!read) // exhausted |
1 | 1143 |
break; |
0 | 1144 |
|
1 | 1145 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
1146 |
lua_pushlstring (cb->L, lua_bgread_buffer, read); |
|
1147 |
if (lua_pcall (cb->L, 1, 1, 0)) { |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1148 |
scr_log_print (LPRINT_LOGNORM, "lua: Bgread callback execution error: %s", lua_tostring (cb->L, -1)); |
1 | 1149 |
lua_pop (cb->L, 1); |
1150 |
return FALSE; |
|
1151 |
} |
|
1152 |
ret = lua_toboolean (cb->L, -1); |
|
1153 |
lua_pop (cb->L, 1); |
|
1154 |
if (!ret) // enough |
|
1155 |
return FALSE; |
|
1156 |
} |
|
1157 |
} |
|
0 | 1158 |
|
1 | 1159 |
if (condition & ~G_IO_IN) { // err or hup |
1160 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
|
1161 |
lua_pushnil (cb->L); |
|
1162 |
if (lua_pcall (cb->L, 1, 1, 0)) { |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1163 |
scr_log_print (LPRINT_LOGNORM, "lua: Bgread callback execution error: %s", lua_tostring (cb->L, -1)); |
1 | 1164 |
lua_pop (cb->L, 1); |
1165 |
return FALSE; |
|
1166 |
} |
|
1167 |
ret = lua_toboolean (cb->L, -1); |
|
1168 |
lua_pop (cb->L, 1); |
|
1169 |
} |
|
0 | 1170 |
|
1 | 1171 |
return ret; |
0 | 1172 |
} |
1173 |
||
1174 |
/// main.bgread |
|
1 | 1175 |
/// Runs specified command and passes its output to a given function. |
0 | 1176 |
/// A: string (command), background reading function |
1177 |
static int lua_main_bgread (lua_State *L) |
|
1178 |
{ |
|
1 | 1179 |
const char *command = luaL_checkstring (L, 1); |
1180 |
lua_bgread_callback_t *cb; |
|
1181 |
FILE *fd; |
|
1182 |
GIOChannel *channel; |
|
1183 |
const char *charset = NULL; |
|
80
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1184 |
guint source; |
1 | 1185 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
0 | 1186 |
|
1 | 1187 |
fd = popen (command, "r"); |
1188 |
if (!fd) { |
|
1189 |
lua_pushstring (L, "Error opening pipe"); |
|
1190 |
lua_error (L); |
|
1191 |
} |
|
0 | 1192 |
|
1 | 1193 |
channel = g_io_channel_unix_new (fileno (fd)); |
1194 |
// We, most likely, need this, |
|
1195 |
// But we cannot use this, |
|
1196 |
// It will block. |
|
1197 |
//if (!g_get_charset (&charset)) |
|
1198 |
g_io_channel_set_encoding (channel, charset, NULL); |
|
1199 |
g_io_channel_set_buffered (channel, FALSE); |
|
1200 |
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); |
|
1201 |
g_io_channel_set_close_on_unref (channel, TRUE); |
|
0 | 1202 |
|
1 | 1203 |
cb = luaL_malloc (L, sizeof (lua_bgread_callback_t)); |
1204 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
|
1205 |
cb->L = L; |
|
1206 |
cb->fd = fd; |
|
0 | 1207 |
|
80
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1208 |
source = g_io_add_watch_full (channel, MLUA_SOURCE_PRIORITY, G_IO_IN|G_IO_HUP|G_IO_ERR, (GIOFunc) lua_bgread_callback, cb, (GDestroyNotify) lua_bgread_callback_destroy); |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1209 |
cb->source = source; |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1210 |
lua_bgreads = g_slist_prepend (lua_bgreads, (gpointer) source); |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1211 |
|
83
794e54ea1022
Package/module name change
Myhailo Danylenko <isbear@ukrpost.net>
parents:
81
diff
changeset
|
1212 |
// unref? |
794e54ea1022
Package/module name change
Myhailo Danylenko <isbear@ukrpost.net>
parents:
81
diff
changeset
|
1213 |
|
1 | 1214 |
return 0; |
0 | 1215 |
} |
1216 |
||
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1217 |
// HOOKÂ HANDLING |
0 | 1218 |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1219 |
typedef struct { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1220 |
lua_State *L; // lua environment for handler use |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1221 |
int nameref; // reference to hook name string |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1222 |
int cbref; // reference to hook handler function |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1223 |
int selfref; // self-reference to object |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1224 |
guint hid; // hook id for object destruction |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1225 |
} lua_hook_t; |
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1226 |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1227 |
/// hook handler result |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1228 |
/// What to do with hook processing afterwards |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1229 |
/// G: |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1230 |
static const string2enum_t lua_hook_handler_result[] = { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1231 |
{ "proceed", HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1232 |
{ "stop", HOOK_HANDLER_RESULT_NO_MORE_HANDLER }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1233 |
{ "drop", HOOK_HANDLER_RESULT_NO_MORE_HANDLER_DROP_DATA }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1234 |
{ NULL, HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1235 |
}; |
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1236 |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1237 |
/// hook handler priority |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1238 |
/// Feel free to specify just a number instead of some preset value. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1239 |
/// G: |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1240 |
static const string2enum_t lua_hook_handler_priority[] = { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1241 |
{ "high", G_PRIORITY_HIGH }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1242 |
{ "default", G_PRIORITY_DEFAULT }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1243 |
{ "idle-high", G_PRIORITY_HIGH_IDLE }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1244 |
{ "idle", G_PRIORITY_DEFAULT_IDLE }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1245 |
{ "low", G_PRIORITY_LOW }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1246 |
{ NULL, G_PRIORITY_DEFAULT }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1247 |
}; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1248 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1249 |
/// hook function |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1250 |
/// Function to be called, when hook will be processsed. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1251 |
/// XXX: we can provide object as argument, but is this necessary? |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1252 |
/// A: table (arguments hash) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1253 |
/// R: hook handler result |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1254 |
static guint lua_hook_cb (const gchar *hookid, hk_arg_t *args, gpointer data) |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1255 |
{ |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1256 |
lua_hook_t *cb = data; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1257 |
hk_arg_t *arg = args; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1258 |
guint ret = HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1259 |
lua_State *L = cb -> L; |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1260 |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1261 |
if (cb -> cbref == LUA_NOREF) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1262 |
return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1263 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1264 |
lua_rawgeti (L, LUA_REGISTRYINDEX, cb -> cbref); |
75
5eecd8854660
Hook callback use local lua state
Myhailo Danylenko <isbear@ukrpost.net>
parents:
72
diff
changeset
|
1265 |
if (!lua_isfunction (L, -1)) { |
5eecd8854660
Hook callback use local lua state
Myhailo Danylenko <isbear@ukrpost.net>
parents:
72
diff
changeset
|
1266 |
lua_pop (L, 1); |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1267 |
return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
1 | 1268 |
} |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1269 |
|
1 | 1270 |
lua_newtable (L); |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1271 |
lua_pushliteral (L, "hook"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1272 |
lua_pushstring (L, hookid); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1273 |
lua_settable (L, -3); |
1 | 1274 |
while (arg->name != NULL) { |
13 | 1275 |
char *name = from_utf8 (arg->name); |
1276 |
char *value = from_utf8 (arg->value); |
|
1277 |
lua_pushstring (L, name); |
|
1278 |
lua_pushstring (L, value); |
|
1 | 1279 |
lua_settable (L, -3); |
13 | 1280 |
g_free (name); |
1281 |
g_free (value); |
|
1 | 1282 |
arg++; |
1283 |
} |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1284 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1285 |
if (lua_pcall (L, 1, 1, 0)) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1286 |
scr_log_print (LPRINT_NORMAL, "lua: Error in hook handler: %s", lua_tostring (L, -1)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1287 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1288 |
} else { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1289 |
switch (lua_type (L, -1)) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1290 |
case LUA_TSTRING: |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1291 |
case LUA_TNUMBER: |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1292 |
ret = luaL_checkenum (L, -1, lua_hook_handler_result); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1293 |
break; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1294 |
default: |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1295 |
ret = HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1296 |
break; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1297 |
} |
75
5eecd8854660
Hook callback use local lua state
Myhailo Danylenko <isbear@ukrpost.net>
parents:
72
diff
changeset
|
1298 |
lua_pop (L, 1); |
1 | 1299 |
} |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1300 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1301 |
return ret; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1302 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1303 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1304 |
/// main.hook |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1305 |
/// Installs hook handler, returns an object, that you need to keep until |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1306 |
/// hook handling is no more needed. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1307 |
/// A: string (hook name), hook function, integer (priority, optional) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1308 |
/// R: userdata (hook object) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1309 |
static int lua_main_hook (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1310 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1311 |
const char *hook_name = luaL_checkstring (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1312 |
int priority = G_PRIORITY_DEFAULT; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1313 |
lua_hook_t *cb; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1314 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1315 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1316 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1317 |
if (lua_gettop (L) > 2) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1318 |
priority = luaL_checkenum (L, 3, lua_hook_handler_priority); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1319 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1320 |
cb = lua_newuserdata (L, sizeof (lua_hook_t)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1321 |
luaL_getmetatable (L, "mcabber.hook"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1322 |
lua_setmetatable (L, -2); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1323 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1324 |
lua_pushvalue (L, -1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1325 |
cb -> selfref = luaL_ref (L, LUA_REGISTRYINDEX); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1326 |
lua_pushvalue (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1327 |
cb -> nameref = luaL_ref (L, LUA_REGISTRYINDEX); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1328 |
lua_pushvalue (L, 2); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1329 |
cb -> cbref = luaL_ref (L, LUA_REGISTRYINDEX); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1330 |
cb -> L = L; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1331 |
cb -> hid = hk_add_handler (lua_hook_cb, hook_name, priority, cb); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1332 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1333 |
return 1; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1334 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1335 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1336 |
static void lua_mcabber_unregister_hook (lua_State *L, lua_hook_t *cb) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1337 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1338 |
const char *name; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1339 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1340 |
if (!cb -> hid || cb -> nameref == LUA_NOREF) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1341 |
return; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1342 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1343 |
lua_rawgeti (L, LUA_REGISTRYINDEX, cb -> nameref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1344 |
name = lua_tostring (L, -1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1345 |
if (name) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1346 |
hk_del_handler (name, cb -> hid); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1347 |
cb -> hid = 0; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1348 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1349 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1350 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1351 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1352 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1353 |
/// hook:del |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1354 |
/// Unregisters given hook handler from mcabber. Object will be destroyed later. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1355 |
static int lua_mcabber_hook_del (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1356 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1357 |
lua_hook_t *cb = luaL_checkudata (L, 1, "mcabber.hook"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1358 |
luaL_argcheck (L, cb != NULL, 1, "mcabber hook object expected"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1359 |
lua_mcabber_unregister_hook (L, cb); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1360 |
if (cb -> selfref != LUA_NOREF) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1361 |
luaL_unref (L, LUA_REGISTRYINDEX, cb -> selfref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1362 |
cb -> selfref = LUA_NOREF; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1363 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1364 |
return 0; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1365 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1366 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1367 |
static int lua_mcabber_hook_gc (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1368 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1369 |
lua_hook_t *cb = luaL_checkudata (L, 1, "mcabber.hook"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1370 |
luaL_argcheck (L, cb != NULL, 1, "mcabber hook object expected"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1371 |
lua_mcabber_unregister_hook (L, cb); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1372 |
if (cb -> nameref != LUA_NOREF) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1373 |
luaL_unref (L, LUA_REGISTRYINDEX, cb -> nameref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1374 |
if (cb -> cbref != LUA_NOREF) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1375 |
luaL_unref (L, LUA_REGISTRYINDEX, cb -> cbref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1376 |
return 0; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1377 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1378 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1379 |
static const luaL_Reg lua_mcabber_hook_reg_m[] = { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1380 |
{ "del", lua_mcabber_hook_del }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1381 |
{ "__gc", lua_mcabber_hook_gc }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1382 |
{ NULL, NULL }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1383 |
}; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1384 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1385 |
static void lua_hook_init (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1386 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1387 |
luaL_newmetatable (L, "mcabber.hook"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1388 |
lua_pushvalue (L, -1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1389 |
lua_setfield (L, -2, "__index"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1390 |
luaL_register (L, NULL, lua_mcabber_hook_reg_m); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1391 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1392 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1393 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1394 |
#if 0 |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1395 |
// OPTION GUARDS |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1396 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1397 |
GSList *lua_installed_guards = NULL; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1398 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1399 |
typedef struct { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1400 |
lua_State *L; // lua environment for handler use |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1401 |
int nameref; // reference to key name string |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1402 |
int cbref; // reference to guard function |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1403 |
// int objref; // self_reference to object |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1404 |
guint hid; // hook id for object destruction |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1405 |
} lua_guard_t; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1406 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1407 |
/// guard function |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1408 |
/// Function to be called, when option changes it's value. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1409 |
/// Old option value is still accessible through main.option. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1410 |
/// A: string (key), string (new value) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1411 |
/// R: string (value to save in hash table) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1412 |
static gchar *lua_guard_cb (const gchar *key, const gchar *value) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1413 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1414 |
lua_guard_t *cb = ;// FIXME |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1415 |
lua_State *L = cb -> L; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1416 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1417 |
if (cb -> cbref == LUA_NOREF) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1418 |
return g_strdup (value); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1419 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1420 |
lua_rawgeti (L, LUA_REGISTRYINDEX, cb -> cbref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1421 |
if (!lua_isfunction (L, -1)) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1422 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1423 |
return g_strdup (value); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1424 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1425 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1426 |
lua_pushstring (L, key); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1427 |
lua_psuhstring (L, value); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1428 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1429 |
if (lua_pcall (L, 2, 1, 0)) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1430 |
scr_log_print (LPRINT_NORMAL, "lua: Error in hook handler: %s", lua_tostring (L, -1)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1431 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1432 |
return g_strdup (value); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1433 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1434 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1435 |
return g_strdup (lua_tostring (L, -1)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1436 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1437 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1438 |
/// main.guard |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1439 |
/// Installs option guard for given option. Returns guard object, that |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1440 |
/// should be kept around as long, as guard is needed. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1441 |
/// A: string (option name), guard function |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1442 |
/// R: userdata (guard object) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1443 |
static int lua_main_guard (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1444 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1445 |
const char *name = luaL_checkstring (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1446 |
int priority = G_PRIORITY_DEFAULT; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1447 |
lua_guard_t *cb; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1448 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1449 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1450 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1451 |
cb = lua_newuserdata (L, sizeof (lua_guard_t)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1452 |
luaL_getmetatable (L, "mcabber.guard"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1453 |
lua_setmetatable (L, -2); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1454 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1455 |
lua_pushvalue (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1456 |
cb -> nameref = luaL_ref (L, LUA_REGISTRYINDEX); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1457 |
lua_pushvalue (L, 2); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1458 |
cb -> cbref = luaL_ref (L, LUA_REGISTRYINDEX); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1459 |
cb -> L = L; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1460 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1461 |
settings_set_guard (name, lua_guard_cb) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1462 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1463 |
return 1; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1464 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1465 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1466 |
static void lua_mcabber_unregister_guard (lua_State *L, lua_guard_t *cb) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1467 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1468 |
const char *name; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1469 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1470 |
if (cb -> nameref == LUA_NOREF) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1471 |
return; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1472 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1473 |
lua_rawgeti (L, LUA_REGISTRYINDEX, cb -> nameref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1474 |
name = lua_tostring (L, -1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1475 |
if (name) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1476 |
settings_del_guard (name); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1477 |
luaL_unref (L, LUA_REGISTRYINDEX, cb -> nameref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1478 |
cb -> nameref = LUA_NOREF; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1479 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1480 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1481 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1482 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1483 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1484 |
/// guard:del |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1485 |
/// Unregisters given option guard from mcabber. Object will be destroyed later. |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1486 |
static int lua_mcabber_guard_del (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1487 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1488 |
lua_guard_t *cb = luaL_checkudata (L, 1, "mcabber.guard"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1489 |
luaL_argcheck (L, cb != NULL, 1, "mcabber guard object expected"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1490 |
lua_mcabber_unregister_guard (L, cb); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1491 |
return 0; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1492 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1493 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1494 |
static int lua_mcabber_guard_gc (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1495 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1496 |
lua_hook_t *cb = luaL_checkudata (L, 1, "mcabber.guard"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1497 |
luaL_argcheck (L, cb != NULL, 1, "mcabber guard object expected"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1498 |
lua_mcabber_unregister_guard (L, cb); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1499 |
if (cb -> cbref != LUA_NOREF) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1500 |
luaL_unref (L, LUA_REGISTRYINDEX, cb -> cbref); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1501 |
return 0; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1502 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1503 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1504 |
static const luaL_Reg lua_mcabber_hook_reg_m[] = { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1505 |
{ "del", lua_mcabber_guard_del }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1506 |
{ "__gc", lua_mcabber_guard_gc }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1507 |
{ NULL, NULL }, |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1508 |
}; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1509 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1510 |
static void lua_guard_init (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1511 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1512 |
luaL_newmetatable (L, "mcabber.guard"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1513 |
lua_pushvalue (L, -1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1514 |
lua_setfield (L, -2, "__index"); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1515 |
luaL_register (L, NULL, lua_mcabber_guard_reg_m); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1516 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1517 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1518 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1519 |
static void lua_guard_uninit (lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1520 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1521 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1522 |
#endif |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1523 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1524 |
// MAIN INITIALIZATION CODE |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1525 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1526 |
#ifdef LLM_LOG_HANDLER |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1527 |
// FIXME: this should not be here |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1528 |
guint lua_lm_log_handler_id; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1529 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1530 |
void lua_lm_log_handler (const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer ignore) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1531 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1532 |
if (settings_opt_get_int ("lua_lm_debug")) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1533 |
scr_log_print (LPRINT_LOGNORM, "%s: %s", domain, message); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1534 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1535 |
#endif |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1536 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1537 |
static void do_lua(char *arg, lua_State *L) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1538 |
{ |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1539 |
if (luaL_loadbuffer (L, arg, strlen (arg), "line")) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1540 |
scr_log_print (LPRINT_LOGNORM, "lua: Compilation error: %s", lua_tostring (L, -1)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1541 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1542 |
return; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1543 |
} |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1544 |
|
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1545 |
if (lua_pcall (L, 0, 0, 0)) { |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1546 |
scr_log_print (LPRINT_NORMAL, "lua: Runtime error: %s", lua_tostring(L, -1)); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1547 |
lua_pop (L, 1); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1548 |
return; |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1549 |
} |
1 | 1550 |
} |
1551 |
||
1552 |
static void *lua_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
|
1553 |
if (nsize == 0) { |
|
1554 |
g_free (ptr); |
|
1555 |
return NULL; |
|
1556 |
} else |
|
1557 |
return g_realloc (ptr, nsize); |
|
0 | 1558 |
} |
1559 |
||
10 | 1560 |
#define reg(NAME) \ |
1561 |
{ #NAME, lua_main_##NAME }, |
|
0 | 1562 |
static const luaL_Reg lua_reg_main[] = { |
40 | 1563 |
reg ( yesno ) |
94
0379139a2003
Forgotten ifdefs (reported by McKael)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
93
diff
changeset
|
1564 |
#ifdef LLM_CONNECTION_ENABLE |
40 | 1565 |
reg ( connection ) |
94
0379139a2003
Forgotten ifdefs (reported by McKael)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
93
diff
changeset
|
1566 |
#endif |
40 | 1567 |
reg ( log ) |
1568 |
reg ( option ) |
|
1569 |
reg ( alias ) |
|
1570 |
reg ( binding ) |
|
1571 |
reg ( fileoption ) |
|
1572 |
reg ( add_feature ) |
|
1573 |
reg ( del_feature ) |
|
52 | 1574 |
reg ( event ) |
40 | 1575 |
reg ( parse_args ) |
1576 |
reg ( add_category ) |
|
1577 |
reg ( del_category ) |
|
1578 |
reg ( add_completion ) |
|
1579 |
reg ( del_completion ) |
|
1580 |
reg ( command ) |
|
1581 |
reg ( print_info ) |
|
1582 |
reg ( beep ) |
|
1583 |
reg ( run ) |
|
1584 |
reg ( status ) |
|
1585 |
reg ( roster ) |
|
1586 |
reg ( current_buddy ) |
|
1587 |
reg ( full_jid ) |
|
1588 |
reg ( buddy_info ) |
|
1589 |
reg ( timer ) |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1590 |
reg ( alias ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1591 |
reg ( binding ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1592 |
reg ( fileoption ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1593 |
reg ( add_feature ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1594 |
reg ( del_feature ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1595 |
reg ( event ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1596 |
reg ( parse_args ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1597 |
reg ( add_category ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1598 |
reg ( del_category ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1599 |
reg ( add_completion ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1600 |
reg ( del_completion ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1601 |
reg ( command ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1602 |
reg ( print_info ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1603 |
reg ( beep ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1604 |
reg ( run ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1605 |
reg ( status ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1606 |
reg ( roster ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1607 |
reg ( current_buddy ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1608 |
reg ( full_jid ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1609 |
reg ( buddy_info ) |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1610 |
reg ( timer ) |
40 | 1611 |
reg ( bgread ) |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1612 |
reg ( hook ) |
10 | 1613 |
{ NULL, NULL }, |
0 | 1614 |
}; |
10 | 1615 |
#undef reg |
1616 |
||
0 | 1617 |
const gchar *g_module_check_init (GModule *module) |
1618 |
{ |
|
1 | 1619 |
lua = lua_newstate (lua_alloc, NULL); |
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1620 |
if (!lua) |
1 | 1621 |
return "Lua initialization error"; |
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1622 |
else |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1623 |
return NULL; |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1624 |
} |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1625 |
|
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1626 |
void g_module_unload (GModule *module) |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1627 |
{ |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1628 |
if (lua) { |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1629 |
lua_close (lua); |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1630 |
lua = NULL; |
1 | 1631 |
} |
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1632 |
} |
0 | 1633 |
|
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1634 |
static void mlua_init (void) |
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1635 |
{ |
1 | 1636 |
luaL_openlibs (lua); |
0 | 1637 |
|
1 | 1638 |
luaL_register (lua, "main", lua_reg_main); |
1639 |
lua_pop (lua, 1); // XXX |
|
1640 |
lua_register (lua, "dopath", lua_global_dopath); |
|
1641 |
lua_register (lua, "print", lua_global_print ); |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1642 |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1643 |
{ |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1644 |
int cid = compl_new_category (); |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1645 |
|
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1646 |
if (cid) { |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1647 |
const string2enum_t *word = lua_yesno; |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1648 |
lua_completion_type[MLUA_YESNO_POS].value = cid; |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1649 |
lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) cid); |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1650 |
while (word->string) { |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1651 |
compl_add_category_word (cid, word->string); |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1652 |
++word; |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1653 |
} |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1654 |
} |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1655 |
} |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1656 |
|
11 | 1657 |
cmd_add ("lua", "Evaluate lua string", 0, 0, (void (*) (char *p)) do_lua, lua); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1658 |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1659 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1660 |
// FIXME: this should not be here. |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1661 |
lua_lm_log_handler_id = g_log_set_handler ("lua-lm", G_LOG_LEVEL_MASK, (GLogFunc) lua_lm_log_handler, NULL); |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1662 |
#endif |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1663 |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1664 |
lua_hook_init (lua); |
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1665 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1666 |
{ |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1667 |
char *initfile = expand_filename (settings_opt_get ("lua_init_filename")); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1668 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1669 |
if (!initfile) |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1670 |
scr_log_print (LPRINT_LOGNORM, "lua: Cannot determine config file name"); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1671 |
else { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1672 |
if (luaL_loadfile(lua, initfile)) { |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1673 |
scr_log_print (LPRINT_LOGNORM, "lua: Unable to compile rc file: %s", lua_tostring (lua, -1)); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1674 |
lua_pop (lua, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1675 |
} else if (lua_pcall (lua, 0, LUA_MULTRET, 0)) { |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1676 |
scr_log_print (LPRINT_LOGNORM, "lua: Runtime error in rc file: %s", lua_tostring(lua, -1)); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1677 |
lua_pop (lua, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1678 |
} else |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1679 |
scr_log_print (LPRINT_LOGNORM, "lua: Loaded %s", initfile); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1680 |
g_free (initfile); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1681 |
} |
1 | 1682 |
} |
0 | 1683 |
|
6 | 1684 |
{ |
1685 |
hk_arg_t args[] = { |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1686 |
{ NULL, NULL }, |
6 | 1687 |
}; |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1688 |
hk_run_handlers("hook-lua-start", args); |
1 | 1689 |
} |
0 | 1690 |
} |
1691 |
||
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1692 |
static void lua_events_cancel (gpointer data, gpointer ignore) |
52 | 1693 |
{ |
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1694 |
lua_event_callback_t *cb = data; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1695 |
const char *evid; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1696 |
if (cb->evid == LUA_NOREF) |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1697 |
return; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1698 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->evid); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1699 |
evid = lua_tostring (cb ->L, -1); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1700 |
evs_callback (evid, EVS_CONTEXT_CANCEL, "Module unloading"); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1701 |
} |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1702 |
|
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1703 |
static void lua_events_destroy (gpointer data, gpointer ignore) |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1704 |
{ |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1705 |
lua_event_callback_t *cb = data; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1706 |
const char *evid; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1707 |
if (cb->evid == LUA_NOREF) |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1708 |
return; |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1709 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->evid); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1710 |
evid = lua_tostring (cb ->L, -1); |
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1711 |
evs_del (evid); |
52 | 1712 |
} |
1713 |
||
80
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1714 |
static void lua_bgreads_destroy (guint source, gpointer ignore) |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1715 |
{ |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1716 |
g_source_remove (source); |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1717 |
} |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1718 |
|
29 | 1719 |
static void lua_timers_destroy (guint source, gpointer ignore) |
1720 |
{ |
|
1721 |
g_source_remove (source); |
|
1722 |
} |
|
1723 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1724 |
static void lua_features_destroy (char *xmlns, gpointer ignore) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1725 |
{ |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1726 |
xmpp_del_feature (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1727 |
g_free (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1728 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1729 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1730 |
static void lua_commands_destroy (char *name, gpointer ignore) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1731 |
{ |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1732 |
lua_command_callback_t *cb = cmd_del (name); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1733 |
if (cb) { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1734 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1735 |
luaL_free (cb->L, cb); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1736 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1737 |
g_free (name); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1738 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1739 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1740 |
static void lua_categories_destroy (guint id, gpointer ignore) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1741 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1742 |
compl_del_category (id); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1743 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1744 |
|
93
0a10228296c1
New module loading scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents:
92
diff
changeset
|
1745 |
static void mlua_uninit (void) |
0 | 1746 |
{ |
1 | 1747 |
if (lua) { |
6 | 1748 |
hk_arg_t args[] = { |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1749 |
{ NULL, NULL }, |
6 | 1750 |
}; |
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1751 |
hk_run_handlers ("hook-lua-quit", args); |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1752 |
|
97
b00f9ce82016
Update hooks interface according to upstream
Myhailo Danylenko <isbear@ukrpost.net>
parents:
95
diff
changeset
|
1753 |
// hook handlers will be unregistered upon objects destruction |
0 | 1754 |
|
80
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1755 |
g_slist_foreach (lua_bgreads, (GFunc) lua_bgreads_destroy, NULL); |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1756 |
g_slist_free (lua_bgreads); |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1757 |
lua_bgreads = NULL; |
c8271a839357
Added bgread destroying on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
78
diff
changeset
|
1758 |
|
29 | 1759 |
g_slist_foreach (lua_timers, (GFunc) lua_timers_destroy, NULL); |
1760 |
g_slist_free (lua_timers); |
|
1761 |
lua_timers = NULL; |
|
1762 |
||
92
5d691423c8a6
New events interface (ugly, untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
88
diff
changeset
|
1763 |
g_slist_foreach (lua_events, (GFunc) lua_events_cancel, NULL); |
52 | 1764 |
g_slist_foreach (lua_events, (GFunc) lua_events_destroy, NULL); |
1765 |
g_slist_free (lua_events); |
|
1766 |
lua_events = NULL; |
|
1767 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1768 |
g_slist_foreach (lua_added_features, (GFunc) lua_features_destroy, NULL); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1769 |
g_slist_free (lua_added_features); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1770 |
lua_added_features = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1771 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1772 |
g_slist_foreach (lua_added_commands, (GFunc) lua_commands_destroy, NULL); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1773 |
g_slist_free (lua_added_commands); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1774 |
lua_added_commands = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1775 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1776 |
g_slist_foreach (lua_added_categories, (GFunc) lua_categories_destroy, NULL); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1777 |
g_slist_free (lua_added_categories); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1778 |
lua_added_categories = NULL; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1779 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1780 |
cmd_del ("lua"); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1781 |
|
1 | 1782 |
lua_close (lua); |
1783 |
lua = NULL; |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1784 |
|
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1785 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1786 |
// FIXME: shouldn't be here |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1787 |
g_log_remove_handler ("lua-lm", lua_lm_log_handler_id); |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1788 |
#endif |
1 | 1789 |
} |
0 | 1790 |
} |
1791 |