author | Myhailo Danylenko <isbear@ukrpost.net> |
Fri, 20 Mar 2009 19:39:34 +0200 | |
changeset 40 | 4e598287dec4 |
parent 39 | 0d43f33243cc |
child 52 | 50d4e9bc622d |
permissions | -rw-r--r-- |
0 | 1 |
|
2 |
#include <glib.h> |
|
3 |
#include <gmodule.h> |
|
4 |
#include <lua.h> |
|
5 |
#include <lauxlib.h> |
|
6 |
#include <lualib.h> |
|
1 | 7 |
#include <stdio.h> |
8 |
#include <stdlib.h> // getenv |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
9 |
#include <string.h> // strcmp |
0 | 10 |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
11 |
#include "config.h" |
1 | 12 |
#include "util.h" |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
13 |
#include "logprint.h" // scr_LogPrint |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
14 |
#include "screen.h" // scr_Beep, scr_WriteIncomingMessage |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
15 |
#include "hbuf.h" // HBB_PREFIX_INFO |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
16 |
#include "commands.h" // process_command, cmd_add, cmd_del |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
17 |
#include "xmpp.h" // xmpp_getstatus, xmpp_getstatusmsg, lconnection |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
18 |
#include "xmpp_helper.h" // xmpp_add_feature, xmpp_del_feature |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
19 |
#include "roster.h" // imstatus2char, foreach_buddy, buddy_*, current_buddy, BUDDATA, ROSTER_TYPE_* |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
20 |
#include "utils.h" // from_utf8, jidtodisp |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
21 |
#include "hooks.h" // hk_add_handler, hk_del_handler |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
22 |
#include "settings.h" // settings_set, settings_del, settings_get |
8 | 23 |
#include "compl.h" // compl_new_category, compl_add_category_word, compl_del_category_word |
0 | 24 |
|
25 |
||
1 | 26 |
// global lua state object, necessary for uninitialization function |
27 |
static lua_State *lua = NULL; |
|
0 | 28 |
|
1 | 29 |
// caller sould g_free result |
18
ba74a9aadaf4
Fix namespace for config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
17
diff
changeset
|
30 |
static char *mcabber_config_filename (const char *file) |
0 | 31 |
{ |
1 | 32 |
const char *home = getenv ("HOME"); |
33 |
if (!home) |
|
34 |
return NULL; |
|
35 |
return g_strconcat (home, "/.mcabber/", file ? file : "", NULL); |
|
0 | 36 |
} |
37 |
||
38 |
/// print |
|
1 | 39 |
/// Prints its arguments to log with default priority. |
40 |
/// A: string/number, ... |
|
0 | 41 |
static int lua_global_print (lua_State *L) |
42 |
{ |
|
1 | 43 |
lua_concat (L, lua_gettop (L)); |
13 | 44 |
scr_LogPrint (LPRINT_LOGNORM | LPRINT_NOTUTF8, lua_tostring (L, -1)); |
1 | 45 |
return 0; |
0 | 46 |
} |
47 |
||
48 |
/// dopath |
|
49 |
/// Loads lua file from default location. |
|
13 | 50 |
/// XXX: g_filename_from_utf8? |
0 | 51 |
/// A: string (filename, without ".lua") |
6 | 52 |
/// R: string (error message, optional) |
0 | 53 |
static int lua_global_dopath (lua_State *L) |
54 |
{ |
|
1 | 55 |
const char *name = luaL_checkstring (L, 1); |
56 |
size_t size = lua_objlen (L, 1); |
|
57 |
char *path; |
|
6 | 58 |
int ret = 0; |
33 | 59 |
if (size > 4 && !strncmp (name + size - 4, ".lua", 4)) |
1 | 60 |
path = mcabber_config_filename (name); |
61 |
else { |
|
62 |
char *fname = g_strconcat (name, ".lua", NULL); |
|
63 |
path = mcabber_config_filename (fname); |
|
64 |
g_free (fname); |
|
65 |
} |
|
66 |
||
6 | 67 |
if (ret = luaL_loadfile (L, path)) |
1 | 68 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Unable to compile file %s: %s", path, lua_tostring (L, -1)); |
6 | 69 |
else if (ret = lua_pcall (lua, 0, LUA_MULTRET, 0)) |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
70 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Runtime error in file %s: %s", path, lua_tostring (L, -1)); |
6 | 71 |
g_free (path); |
1 | 72 |
|
6 | 73 |
if (ret) |
74 |
return 1; |
|
75 |
else |
|
76 |
return 0; |
|
0 | 77 |
} |
78 |
||
31
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
79 |
/// yes or no ansvers |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
80 |
/// G: |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
81 |
static const string2enum_t lua_yesno[] = { |
39 | 82 |
{ "1", 1 }, |
83 |
{ "0", 0 }, |
|
31
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
84 |
{ "enable", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
85 |
{ "disable", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
86 |
{ "true", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
87 |
{ "false", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
88 |
{ "on", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
89 |
{ "off", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
90 |
{ "yes", 1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
91 |
{ "no", 0 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
92 |
{ NULL, -1 }, |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
93 |
}; |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
94 |
|
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
95 |
/// main.yesno |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
96 |
/// 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
|
97 |
/// If ansver is not recognized, returns nil. |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
98 |
/// A: anything (string expected) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
99 |
/// R: boolean or nil |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
100 |
static int lua_main_yesno (lua_State *L) |
0 | 101 |
{ |
31
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
102 |
int type = lua_type (L, 1); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
103 |
if (type == LUA_TSTRING) { |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
104 |
int ret = luaL_checkenum (L, 1, lua_yesno); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
105 |
if (ret == -1) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
106 |
lua_pushnil (L); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
107 |
else |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
108 |
lua_pushboolean (L, ret); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
109 |
} else if (type == LUA_TNUMBER) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
110 |
lua_pushboolean (L, lua_tointeger (L, 1)); |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
111 |
else if (type != LUA_TBOOLEAN) |
54957980a83a
yesno in C, no config_file
Myhailo Danylenko <isbear@ukrpost.net>
parents:
30
diff
changeset
|
112 |
lua_pushnil (L); |
1 | 113 |
return 1; |
0 | 114 |
} |
115 |
||
116 |
/// log print type |
|
1 | 117 |
/// G: |
0 | 118 |
static const string2enum_t lua_lprint[] = { |
1 | 119 |
{ "normal", LPRINT_NORMAL }, |
120 |
{ "log", LPRINT_LOG }, |
|
121 |
{ "debug", LPRINT_DEBUG }, |
|
122 |
{ "notutf0", LPRINT_NOTUTF8 }, |
|
123 |
{ NULL, 0 }, |
|
0 | 124 |
}; |
125 |
||
1 | 126 |
/// roster type |
127 |
/// G: |
|
0 | 128 |
static const string2enum_t lua_roster_type[] = { |
1 | 129 |
{ "user", ROSTER_TYPE_USER }, |
130 |
{ "group", ROSTER_TYPE_GROUP }, |
|
131 |
{ "agent", ROSTER_TYPE_AGENT }, |
|
132 |
{ "room", ROSTER_TYPE_ROOM }, |
|
133 |
{ "special", ROSTER_TYPE_SPECIAL }, |
|
134 |
{ NULL, 0 }, |
|
0 | 135 |
}; |
136 |
||
137 |
/// main.log |
|
138 |
/// Prints message to log. |
|
13 | 139 |
/// Note: most likely you need notutf8 flag enabled. |
0 | 140 |
/// A: log print type, message, message... |
141 |
static int lua_main_log (lua_State *L) |
|
142 |
{ |
|
1 | 143 |
int type = luaL_checkenum_multi (L, 1, lua_lprint); |
144 |
lua_concat (L, lua_gettop (L) - 1); |
|
145 |
scr_LogPrint (type, lua_tostring (L, -1)); |
|
146 |
return 0; |
|
0 | 147 |
} |
148 |
||
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
149 |
// expects table on top |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
150 |
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
|
151 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
152 |
char *loc = from_utf8 (key); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
153 |
lua_pushstring (L, loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
154 |
g_free (loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
155 |
loc = from_utf8 (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
156 |
lua_pushstring (L, loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
157 |
g_free (loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
158 |
lua_settable (L, -3); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
159 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
160 |
|
0 | 161 |
/// main.option |
162 |
/// Sets or gets value of mcabber option. |
|
163 |
/// 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
|
164 |
/// 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
|
165 |
/// A: string (option name, optional), string (value, optional) |
0 | 166 |
/// R: string (value, optional) |
167 |
static int lua_main_option (lua_State *L) |
|
168 |
{ |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
169 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
170 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
171 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
172 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
173 |
if (lua_type (L, 2) == LUA_TNIL) // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
174 |
settings_del (SETTINGS_TYPE_OPTION, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
175 |
else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
176 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
177 |
settings_set (SETTINGS_TYPE_OPTION, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
178 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
179 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
180 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
181 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
182 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
183 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_OPTION, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
184 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
185 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
186 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
187 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
188 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
189 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
190 |
return 1; |
1 | 191 |
} |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
192 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
193 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
194 |
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
|
195 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
196 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
197 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
198 |
|
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
199 |
/// main.alias |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
200 |
/// Sets or gets alias. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
201 |
/// You can specify nil as a command to delete alias. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
202 |
/// 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
|
203 |
/// A: string (alias name, optional), string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
204 |
/// R: string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
205 |
static int lua_main_alias (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
206 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
207 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
208 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
209 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
210 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
211 |
if (lua_type (L, 2) == LUA_TNIL) { // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
212 |
settings_del (SETTINGS_TYPE_ALIAS, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
213 |
compl_del_category_word (COMPL_CMD, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
214 |
} else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
215 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
216 |
if (!settings_get (SETTINGS_TYPE_ALIAS, name)) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
217 |
compl_add_category_word (COMPL_CMD, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
218 |
settings_set (SETTINGS_TYPE_ALIAS, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
219 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
220 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
221 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
222 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
223 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
224 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_ALIAS, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
225 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
226 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
227 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
228 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
229 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
230 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
231 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
232 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
233 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
234 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
235 |
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
|
236 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
237 |
} |
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 |
|
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
240 |
/// main.bind |
15 | 241 |
/// Sets or gets binding. |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
242 |
/// You can specify nil as a command to unbind key. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
243 |
/// 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
|
244 |
/// A: string (keycode, optional), string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
245 |
/// R: string (command, optional) |
15 | 246 |
static int lua_main_binding (lua_State *L) |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
247 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
248 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
249 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
250 |
// just to be sure... |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
251 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
252 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
253 |
if (lua_type (L, 2) == LUA_TNIL) // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
254 |
settings_del (SETTINGS_TYPE_BINDING, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
255 |
else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
256 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
257 |
settings_set (SETTINGS_TYPE_BINDING, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
258 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
259 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
260 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
261 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
262 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
263 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_BINDING, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
264 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
265 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
266 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
267 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
268 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
269 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
270 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
271 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
272 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
273 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
274 |
settings_foreach (SETTINGS_TYPE_BINDING, (void (*)(char *key, char *val, void *ud)) lua_options_callback, L); |
1 | 275 |
return 1; |
276 |
} |
|
0 | 277 |
} |
278 |
||
33 | 279 |
/// main.fileoption |
280 |
/// Gets option, expanding it as filename. |
|
281 |
/// A: string (option name) |
|
282 |
/// R: string (expanded option value) or nil |
|
283 |
static int lua_main_fileoption (lua_State *L) |
|
284 |
{ |
|
285 |
char *fname = expand_filename (settings_opt_get (luaL_checkstring (L, 1))); |
|
286 |
if (fname) { |
|
287 |
lua_pushstring (L, fname); |
|
288 |
g_free (fname); |
|
289 |
} else |
|
290 |
lua_pushnil (L); |
|
291 |
return 1; |
|
292 |
} |
|
293 |
||
0 | 294 |
/// main.connection |
295 |
/// Returns lightuserdata of mcabber's loudmouth connection. |
|
296 |
/// This can be very useful with lua-loudmouth, and not much otherwise. |
|
297 |
/// R: lightuserdata |
|
298 |
static int lua_main_connection (lua_State *L) |
|
299 |
{ |
|
1 | 300 |
lua_pushlightuserdata (L, lconnection); |
301 |
return 1; |
|
0 | 302 |
} |
303 |
||
304 |
/// main.print_info |
|
305 |
/// Prints a system message to buddy's window. |
|
306 |
/// A: string (jid), string (message) |
|
307 |
static int lua_main_print_info (lua_State *L) |
|
308 |
{ |
|
13 | 309 |
char *jid = to_utf8 (luaL_checkstring (L, 1)); |
310 |
char *to = jidtodisp (jid); |
|
311 |
char *mesg = to_utf8 (luaL_checkstring (L, 2)); |
|
312 |
scr_WriteIncomingMessage (to, mesg, 0, HBB_PREFIX_INFO, 0); |
|
313 |
g_free (mesg); |
|
1 | 314 |
g_free (to); |
13 | 315 |
g_free (jid); |
1 | 316 |
return 0; |
0 | 317 |
} |
318 |
||
319 |
/// main.beep |
|
320 |
/// Beeps with system speaker. |
|
321 |
static int lua_main_beep (lua_State *L) |
|
322 |
{ |
|
1 | 323 |
scr_Beep (); |
324 |
return 0; |
|
0 | 325 |
} |
326 |
||
327 |
/// main.run |
|
328 |
/// Runs specified mcabber command. |
|
329 |
/// A: string |
|
330 |
static int lua_main_run (lua_State *L) |
|
331 |
{ |
|
1 | 332 |
process_command (luaL_checkstring (L, 1), TRUE); |
333 |
return 0; |
|
0 | 334 |
} |
335 |
||
336 |
/// main.status |
|
337 |
/// Returns your current status. |
|
1 | 338 |
/// R: string (status letter), string (status message) |
0 | 339 |
static int lua_main_status (lua_State *L) |
340 |
{ |
|
1 | 341 |
char *sm = from_utf8 (xmpp_getstatusmsg ()); |
342 |
lua_pushlstring (L, &imstatus2char[xmpp_getstatus ()], 1); |
|
343 |
lua_pushstring (L, sm); |
|
344 |
g_free (sm); |
|
345 |
return 2; |
|
0 | 346 |
} |
347 |
||
1 | 348 |
// expects table on top |
0 | 349 |
static void lua_rosterlist_callback (gpointer buddy, lua_State *L) |
350 |
{ |
|
13 | 351 |
char *jid = from_utf8 (buddy_getjid (buddy)); |
1 | 352 |
lua_pushnumber (L, lua_objlen (L, -1) + 1); |
13 | 353 |
lua_pushstring (L, jid); |
1 | 354 |
lua_settable (L, -3); |
13 | 355 |
g_free (jid); |
0 | 356 |
} |
357 |
||
358 |
/// main.roster |
|
359 |
/// Returns array of jids of buddies in roster. |
|
360 |
/// R: table |
|
361 |
static int lua_main_roster (lua_State *L) |
|
362 |
{ |
|
1 | 363 |
lua_newtable (L); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
364 |
foreach_buddy (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM, (void (*) (gpointer buddy, void *data)) lua_rosterlist_callback, L); |
1 | 365 |
return 1; |
0 | 366 |
} |
367 |
||
368 |
/// main.current_buddy |
|
10 | 369 |
/// Returns jid of current selected buddy or sets current buddy to buddy with specified jid. |
370 |
/// A: string (optional) |
|
371 |
/// R: string (optional) |
|
0 | 372 |
static int lua_main_current_buddy (lua_State *L) |
373 |
{ |
|
10 | 374 |
if (lua_gettop (L) > 0) { // Set |
13 | 375 |
// XXX: we need not convert to utf, RS works on jids/names in locale charset, |
376 |
// but will jidtodisp always correctly work on such tings? |
|
10 | 377 |
char *jid = jidtodisp (luaL_checkstring (L, 1)); |
378 |
scr_RosterSearch (jid); |
|
379 |
g_free (jid); |
|
380 |
return 0; |
|
381 |
} else { // Get |
|
13 | 382 |
char *jid = from_utf8 (buddy_getjid (BUDDATA (current_buddy))); |
383 |
lua_pushstring (L, jid); |
|
384 |
g_free (jid); |
|
10 | 385 |
return 1; |
386 |
} |
|
387 |
} |
|
388 |
||
389 |
/// main.full_jid |
|
390 |
/// Returns full jid (with current resource) of specified buddy (or current, if not specified). |
|
391 |
/// Note, that if there are no resources online, it will return just what it got. |
|
392 |
/// A: string (jid, optional) |
|
393 |
/// R: string (jid) |
|
394 |
static int lua_main_full_jid (lua_State *L) |
|
395 |
{ |
|
40 | 396 |
GList *buddy; |
10 | 397 |
GSList *resources; |
398 |
GSList *resource; |
|
13 | 399 |
if (lua_gettop (L) > 0) { |
400 |
char *jid = from_utf8 (luaL_checkstring (L, 1)); |
|
401 |
buddy = buddy_search_jid (jid); |
|
402 |
g_free (jid); |
|
403 |
} else |
|
10 | 404 |
buddy = current_buddy; |
405 |
if (!buddy) |
|
406 |
return 0; |
|
407 |
resources = buddy_getresources (BUDDATA (buddy)); |
|
408 |
if (!resources) { |
|
13 | 409 |
char *loc = from_utf8 (buddy_getjid (BUDDATA (buddy))); |
410 |
lua_pushstring (L, loc); |
|
411 |
g_free (loc); |
|
412 |
} else { |
|
413 |
char *jid = from_utf8 (buddy_getjid (BUDDATA (buddy))); |
|
414 |
char *res = from_utf8 (g_slist_last (resources)->data); |
|
415 |
lua_pushfstring (L, "%s%c%s", jid, JID_RESOURCE_SEPARATOR, res); |
|
416 |
for (resource = resources; resource; resource = g_slist_next (resource)) |
|
417 |
g_free (resource->data); |
|
418 |
g_slist_free (resources); |
|
419 |
g_free (jid); |
|
420 |
g_free (res); |
|
10 | 421 |
} |
1 | 422 |
return 1; |
0 | 423 |
} |
424 |
||
425 |
typedef struct { |
|
1 | 426 |
lua_State *L; |
427 |
gpointer buddy; |
|
0 | 428 |
} lua_state_and_buddy_t; // :) |
429 |
||
29 | 430 |
/// resources table |
431 |
/// Hash table with resource name as keys and another hash tables as values. |
|
432 |
/// Inner tables contain resource-specific information: priority, status and message. |
|
0 | 433 |
static void lua_buddy_resources_callback (gpointer resource, lua_state_and_buddy_t *d) |
434 |
{ |
|
13 | 435 |
char *loc = from_utf8 (resource); |
436 |
lua_pushstring (d->L, loc); |
|
437 |
g_free (loc); |
|
1 | 438 |
lua_createtable (d->L, 0, 3); |
439 |
lua_pushstring (d->L, "priority"); |
|
440 |
lua_pushnumber (d->L, buddy_getresourceprio (d->buddy, resource)); |
|
441 |
lua_settable (d->L, -3); |
|
442 |
lua_pushstring (d->L, "status"); |
|
443 |
lua_pushlstring (d->L, &imstatus2char[buddy_getstatus (d->buddy, resource)], 1); |
|
444 |
lua_settable (d->L, -3); |
|
445 |
lua_pushstring (d->L, "message"); |
|
13 | 446 |
loc = from_utf8 (buddy_getstatusmsg (d->buddy, resource)); |
447 |
lua_pushstring (d->L, loc); |
|
448 |
g_free (loc); |
|
1 | 449 |
lua_settable (d->L, -3); |
450 |
lua_settable (d->L, -3); |
|
10 | 451 |
g_free (resource); |
0 | 452 |
} |
453 |
||
454 |
/// main.buddy_info |
|
455 |
/// Returns a hash table with information on specified buddy. |
|
29 | 456 |
/// Table contains fields type, name, onserver and resources (which points to resources table). |
0 | 457 |
/// A: string (jid) |
458 |
/// R: table |
|
459 |
static int lua_main_buddy_info (lua_State *L) |
|
460 |
{ |
|
13 | 461 |
char *loc = to_utf8 (luaL_checkstring (L, 1)); |
462 |
char *jid = jidtodisp (loc); |
|
1 | 463 |
GSList *buddy = roster_find (jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
10 | 464 |
GSList *resources; |
1 | 465 |
lua_state_and_buddy_t snb; |
466 |
g_free (jid); |
|
13 | 467 |
g_free (loc); |
1 | 468 |
|
469 |
if (!buddy) { |
|
470 |
lua_pushnil (L); |
|
471 |
return 1; |
|
472 |
} |
|
0 | 473 |
|
1 | 474 |
lua_createtable (L, 0, 3); |
475 |
lua_pushstring (L, "type"); |
|
476 |
luaL_pushenum (L, buddy_gettype (BUDDATA (buddy)), lua_roster_type); |
|
477 |
lua_settable (L, -3); |
|
478 |
lua_pushstring (L, "name"); |
|
13 | 479 |
loc = from_utf8 (buddy_getname (BUDDATA (buddy))); |
480 |
lua_pushstring (L, loc); |
|
481 |
g_free (loc); |
|
1 | 482 |
lua_settable (L, -3); |
483 |
lua_pushstring (L, "onserver"); |
|
484 |
lua_pushboolean (L, buddy_getonserverflag (BUDDATA (buddy))); |
|
485 |
lua_settable (L, -3); |
|
486 |
lua_pushstring (L, "resources"); |
|
487 |
lua_createtable (L, 0, 0); |
|
488 |
snb.L = L; |
|
489 |
snb.buddy = BUDDATA (buddy); |
|
10 | 490 |
resources = buddy_getresources (BUDDATA (buddy)); |
1 | 491 |
g_slist_foreach (buddy_getresources (BUDDATA (buddy)), (GFunc) lua_buddy_resources_callback, &snb); |
10 | 492 |
g_slist_free (resources); |
493 |
lua_settable (L, -3); |
|
1 | 494 |
|
495 |
return 1; |
|
0 | 496 |
} |
497 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
498 |
// XMPP DISCO FEATURES |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
499 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
500 |
GSList *lua_added_features = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
501 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
502 |
/// main.add_feature |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
503 |
/// Adds xmlns to disco#info features list. |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
504 |
/// A: string (xmlns) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
505 |
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
|
506 |
{ |
13 | 507 |
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
|
508 |
xmpp_add_feature (xmlns); |
13 | 509 |
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
|
510 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
511 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
512 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
513 |
/// main.del_feature |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
514 |
/// Removes xmlns from disco#info features list. |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
515 |
/// A: stirng (xmlns) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
516 |
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
|
517 |
{ |
13 | 518 |
char *xmlns = to_utf8 (luaL_checkstring (L, 1)); |
519 |
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
|
520 |
xmpp_del_feature (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
521 |
if (el) { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
522 |
g_free (el->data); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
523 |
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
|
524 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
525 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
526 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
527 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
528 |
// MCABBER COMMANDS |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
529 |
|
9 | 530 |
/// completion type |
531 |
/// Built-it completion types can be specified as string, instead of id. |
|
532 |
/// G: |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
533 |
static string2enum_t lua_completion_type[] = { // not const, we need to modify yesno |
9 | 534 |
{ "cmd", COMPL_CMD }, |
535 |
{ "jid", COMPL_JID }, |
|
536 |
{ "urljid", COMPL_URLJID }, |
|
537 |
{ "name", COMPL_NAME }, |
|
538 |
{ "status", COMPL_STATUS }, |
|
539 |
{ "filename", COMPL_FILENAME }, |
|
540 |
{ "roster", COMPL_ROSTER }, |
|
541 |
{ "buffer", COMPL_BUFFER }, |
|
542 |
{ "group", COMPL_GROUP }, |
|
543 |
{ "groupname", COMPL_GROUPNAME }, |
|
544 |
{ "multiline", COMPL_MULTILINE }, |
|
545 |
{ "room", COMPL_ROOM }, |
|
546 |
{ "resource", COMPL_RESOURCE }, |
|
547 |
{ "auth", COMPL_AUTH }, |
|
548 |
{ "request", COMPL_REQUEST }, |
|
549 |
{ "events", COMPL_EVENTS }, |
|
550 |
{ "eventsid", COMPL_EVENTSID }, |
|
551 |
{ "pgp", COMPL_PGP }, |
|
552 |
{ "color", COMPL_COLOR }, |
|
553 |
{ "otr", COMPL_OTR }, |
|
554 |
{ "ortpolicy", COMPL_OTRPOLICY }, |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
555 |
{ "yesno", 0 }, |
9 | 556 |
{ NULL, 0 }, |
557 |
}; |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
558 |
#define MLUA_YESNO_POS ( 21 ) |
9 | 559 |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
560 |
typedef struct { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
561 |
int reference; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
562 |
int parse_args; |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
563 |
lua_State *L; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
564 |
} lua_command_callback_t; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
565 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
566 |
static GSList *lua_added_commands = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
567 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
568 |
static GSList *lua_added_categories = NULL; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
569 |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
570 |
// 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
|
571 |
/// command arguments table |
27 | 572 |
/// It can parse barewords (with escapes), double-quoted strings (with escapes), single-quoted strings (without escapes), options and arguments. |
24 | 573 |
/// Arguments are separated only by whitespace, so, consequential quoted strings or barewords are one argument. |
27 | 574 |
/// This strings are equal: |
24 | 575 |
/// * ab\ cd\'e\\f\" |
576 |
/// * "ab cd'e\\f\"" |
|
27 | 577 |
/// * 'ab cd'\''e\f"' |
578 |
/// * ab" cd'"'e\f"' |
|
579 |
/// Returned table have option names as keys, option values as values, and arguments as sequential members. -- option is supported. |
|
580 |
/// Example: "-t jid -m 9 -- -aa bb cc" will result in { t = 'jid', m = 9, '-aa', 'bb', 'cc' } |
|
581 |
/// Implementation notes: |
|
582 |
/// * All options should be before any arguments. First non-option argument disables options recognizing. |
|
583 |
/// * 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. |
|
584 |
/// * Escape character just before EOL is preserved. |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
585 |
static int luaL_pushargs (lua_State *L, const char *args) |
24 | 586 |
{ |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
587 |
const char *p = args; |
24 | 588 |
luaL_Buffer buf; |
27 | 589 |
int option = 0; |
590 |
int options = 1; |
|
24 | 591 |
|
592 |
lua_newtable (L); |
|
593 |
luaL_buffinit (L, &buf); |
|
594 |
while (*p) { |
|
595 |
if (*p == ' ') { |
|
596 |
++p; |
|
597 |
continue; |
|
598 |
} |
|
599 |
if (*p == '"') { // soft quote |
|
600 |
const char *start = ++p; |
|
601 |
while (*p) { |
|
602 |
if (*p == '\\') { // escape symbol |
|
603 |
luaL_addlstring (&buf, start, p - start); |
|
604 |
start = ++p; |
|
605 |
if (*p) // skip symbol |
|
606 |
++p; |
|
607 |
else // add last \ in line |
|
608 |
luaL_addchar (&buf, '\\'); |
|
609 |
} else if (*p == '"') // quotation end |
|
610 |
break; |
|
611 |
else |
|
612 |
++p; |
|
613 |
} |
|
27 | 614 |
luaL_addlstring (&buf, start, p - start); // XXX: eats quote on eol |
24 | 615 |
if (*p) |
616 |
++p; |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
617 |
else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
618 |
return 1; |
24 | 619 |
} else if (*p == '\'') { // no-escape quote |
620 |
const char *start = ++p; |
|
621 |
while (*p && *p != '\'') |
|
622 |
p++; |
|
27 | 623 |
luaL_addlstring (&buf, start, p - start); // XXX: eats quote on eol |
24 | 624 |
if (*p) |
625 |
++p; |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
626 |
else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
627 |
return 1; |
24 | 628 |
} else { // bareword |
629 |
const char *start = p; |
|
630 |
while (*p) { |
|
631 |
if (*p == '\\') { |
|
632 |
luaL_addlstring (&buf, start, p - start); |
|
633 |
start = ++p; |
|
634 |
if (*p) // skip symbol |
|
635 |
++p; |
|
636 |
else // add last \ in line |
|
637 |
luaL_addchar (&buf, '\\'); |
|
638 |
} else if (*p == ' ' || *p == '\'' || *p == '"') |
|
639 |
break; |
|
640 |
else |
|
641 |
++p; |
|
642 |
} |
|
643 |
luaL_addlstring (&buf, start, p - start); |
|
644 |
} |
|
645 |
||
646 |
if ((!*p) || *p == ' ') { |
|
27 | 647 |
const char *result; |
24 | 648 |
luaL_pushresult (&buf); |
27 | 649 |
|
650 |
result = lua_tostring (L, -1); |
|
651 |
if (options && !option && *result == '-') { // option |
|
652 |
if (*(result+1) == '-' && !*(result+2)) { // end of options |
|
653 |
lua_pop (L, 1); |
|
654 |
options = 0; |
|
655 |
} else { // option name |
|
656 |
lua_pushstring (L, result + 1); |
|
657 |
lua_remove (L, -2); |
|
658 |
option = 1; |
|
659 |
} |
|
660 |
} else if (option) { // opion value |
|
661 |
lua_settable (L, -3); |
|
662 |
option = 0; |
|
663 |
} else { // argument |
|
664 |
options = 0; |
|
665 |
luaL_ref (L, -2); |
|
666 |
} |
|
667 |
||
24 | 668 |
luaL_buffinit (L, &buf); |
669 |
} |
|
670 |
} |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
671 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
672 |
if (option) { |
27 | 673 |
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
|
674 |
return 1; |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
675 |
} |
27 | 676 |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
677 |
return 0; |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
678 |
} |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
679 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
680 |
/// command function |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
681 |
/// Function to handle newly registered command. |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
682 |
/// 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
|
683 |
/// A: string (arguments) or command arguments table |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
684 |
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
|
685 |
{ |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
686 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
687 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
688 |
if (cb->parse_args) |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
689 |
luaL_pushargs (cb->L, args); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
690 |
else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
691 |
lua_pushstring (cb->L, args); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
692 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
693 |
if (lua_pcall (cb->L, 1, 0, 0)) { |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
694 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Command execution error: %s", lua_tostring (cb->L, -1)); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
695 |
lua_pop (cb->L, 1); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
696 |
} |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
697 |
} |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
698 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
699 |
/// main.parse_args |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
700 |
/// 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
|
701 |
/// A: string |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
702 |
/// R: table |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
703 |
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
|
704 |
{ |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
705 |
luaL_pushargs (L, luaL_checkstring (L, 1)); |
24 | 706 |
return 1; |
707 |
} |
|
708 |
||
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
709 |
/// main.add_category |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
710 |
/// Adds completion category. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
711 |
/// A: table (values are used as words for completion, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
712 |
/// R: integer (category id, in fact completion type) or nil |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
713 |
static int lua_main_add_category (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
714 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
715 |
guint cid; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
716 |
|
15 | 717 |
if (lua_gettop (L) > 0) { |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
718 |
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
|
719 |
cid = compl_new_category (); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
720 |
if (cid) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
721 |
lua_pushnil (L); |
17
3a12759a22b1
Fix segfault in add_category
Myhailo Danylenko <isbear@ukrpost.net>
parents:
15
diff
changeset
|
722 |
while (lua_next (L, 1)) { |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
723 |
char *word = to_utf8 (luaL_checkstring (L, -1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
724 |
if (word) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
725 |
compl_add_category_word (cid, word); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
726 |
g_free (word); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
727 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
728 |
lua_pop (L, 1); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
729 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
730 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
731 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
732 |
cid = compl_new_category (); |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
733 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
734 |
if (cid) { |
15 | 735 |
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
|
736 |
lua_pushinteger (L, cid); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
737 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
738 |
lua_pushnil (L); |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
739 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
740 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
741 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
742 |
|
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
743 |
/// main.del_category |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
744 |
/// Removes completion category. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
745 |
/// A: integer (category id) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
746 |
static int lua_main_del_category (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
747 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
748 |
guint cid = luaL_checkinteger (L, 1); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
749 |
compl_del_category (cid); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
750 |
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
|
751 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
752 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
753 |
|
8 | 754 |
/// main.add_completion |
755 |
/// Adds word to a completion list. |
|
756 |
/// A: integer (completion group id), string (word) |
|
757 |
static int lua_main_add_completion (lua_State *L) |
|
758 |
{ |
|
13 | 759 |
guint cid = luaL_checkinteger (L, 1); |
760 |
char *word = to_utf8 (luaL_checkstring (L, 2)); // XXX |
|
8 | 761 |
compl_add_category_word (cid, word); |
13 | 762 |
g_free (word); |
8 | 763 |
} |
764 |
||
765 |
/// main.del_completion |
|
766 |
/// Removes word from a completion list. |
|
767 |
/// A: integer (completion group id), string (word) |
|
768 |
static int lua_main_del_completion (lua_State *L) |
|
769 |
{ |
|
13 | 770 |
guint cid = luaL_checkinteger (L, 1); |
771 |
char *word = to_utf8 (luaL_checkstring (L, 2)); // XXX |
|
8 | 772 |
compl_del_category_word (cid, word); |
13 | 773 |
g_free (word); |
8 | 774 |
} |
775 |
||
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
776 |
/// main.command |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
777 |
/// 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
|
778 |
/// To unregister command omit function argument. |
8 | 779 |
/// If you specify a third argument, table (even empty), function will return completion group id or nothing. |
9 | 780 |
/// You can also specify a string name (see completion type) instead of table, for non-builtin, you can just pass integer id. |
8 | 781 |
/// Note, that for now there are no way to unregister completion group, so, resources can be exausted easily. |
782 |
/// 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
|
783 |
/// A: string (command name), command function (optional), boolean (parse args flag, optional), table (completions, optional)/completion type (or integer comletion group id, optional) |
9 | 784 |
/// 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
|
785 |
static int lua_main_command (lua_State *L) |
39 | 786 |
{ |
13 | 787 |
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
|
788 |
lua_command_callback_t *cb; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
789 |
int top = lua_gettop (L); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
790 |
if (top > 1) { // Register |
8 | 791 |
guint cid = 0; |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
792 |
int parse = 0; |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
793 |
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
|
794 |
|
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
795 |
if (top > 2) { // parse flag provided |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
796 |
parse = lua_toboolean (L, 3); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
797 |
|
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
798 |
if (top > 3) { // Completions provided |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
799 |
if (lua_type (L, 4) == LUA_TTABLE) { |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
800 |
cid = compl_new_category (); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
801 |
if (cid) { |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
802 |
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
|
803 |
lua_pushnil (L); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
804 |
while (lua_next (L, 4)) { |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
805 |
char *word = to_utf8 (luaL_checkstring (L, -1)); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
806 |
compl_add_category_word (cid, word); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
807 |
lua_pop (L, 1); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
808 |
g_free (word); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
809 |
} |
8 | 810 |
} |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
811 |
} else |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
812 |
cid = luaL_checkenum (L, 4, lua_completion_type); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
813 |
} |
8 | 814 |
} |
815 |
||
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
816 |
cb = luaL_malloc (L, sizeof (lua_command_callback_t)); |
8 | 817 |
lua_pushvalue (L, 2); |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
818 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
819 |
cb->parse_args = parse; |
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
820 |
cb->L = L; |
8 | 821 |
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
|
822 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
823 |
lua_added_commands = g_slist_prepend (lua_added_commands, g_strdup (name)); |
8 | 824 |
|
825 |
if (cid) { |
|
9 | 826 |
luaL_pushenum (L, cid, lua_completion_type); |
8 | 827 |
return 1; |
828 |
} |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
829 |
} else { // Unregister |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
830 |
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
|
831 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
832 |
cb = cmd_del (name); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
833 |
if (cb) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
834 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
835 |
luaL_free (cb->L, cb); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
836 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
837 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
838 |
if (el) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
839 |
g_free (el->data); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
840 |
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
|
841 |
} |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
842 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
843 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
844 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
845 |
|
0 | 846 |
// TIMER |
847 |
||
848 |
typedef struct { |
|
1 | 849 |
int reference; |
29 | 850 |
guint source; |
1 | 851 |
lua_State *L; |
0 | 852 |
} lua_timer_callback_t; |
853 |
||
29 | 854 |
static GSList *lua_timers = NULL; |
855 |
||
0 | 856 |
static void lua_timer_callback_destroy (lua_timer_callback_t *cb) |
857 |
{ |
|
1 | 858 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
29 | 859 |
lua_timers = g_slist_remove (lua_timers, (gpointer) cb->source); |
1 | 860 |
luaL_free (cb->L, cb); |
0 | 861 |
} |
862 |
||
863 |
/// timer function |
|
864 |
/// Function, that will be called periodically until it returns false. |
|
865 |
/// R: boolean |
|
866 |
static gboolean lua_timer_callback (lua_timer_callback_t *cb) |
|
867 |
{ |
|
1 | 868 |
int ret; |
869 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
|
870 |
if (lua_pcall (cb->L, 0, 1, 0)) { |
|
871 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Timer callback execution error: %s", lua_tostring (cb->L, -1)); |
|
872 |
lua_pop (cb->L, 1); |
|
873 |
return FALSE; |
|
874 |
} |
|
875 |
ret = lua_toboolean (cb->L, -1); |
|
876 |
lua_pop (cb->L, 1); |
|
877 |
return ret; |
|
0 | 878 |
} |
879 |
||
880 |
/// main.timer |
|
881 |
/// Creates new timer function, that will be called periodically. |
|
882 |
/// A: integer (interval, seconds), timer function |
|
883 |
static int lua_main_timer (lua_State *L) |
|
884 |
{ |
|
1 | 885 |
int interval = luaL_checkint (L, 1); |
29 | 886 |
guint source; |
1 | 887 |
lua_timer_callback_t *cb; |
888 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
|
0 | 889 |
|
1 | 890 |
cb = luaL_malloc (L, sizeof (lua_timer_callback_t)); |
891 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
|
892 |
cb->L = L; |
|
0 | 893 |
|
30
2cf24aced294
Definitions moved to cmake options
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
894 |
source = g_timeout_add_seconds_full (MLUA_SOURCE_PRIORITY, interval, (GSourceFunc) lua_timer_callback, cb, (GDestroyNotify) lua_timer_callback_destroy); |
29 | 895 |
cb->source = source; |
896 |
lua_timers = g_slist_prepend (lua_timers, (gpointer) source); |
|
897 |
||
1 | 898 |
return 0; |
0 | 899 |
} |
900 |
||
901 |
// BACKGROUND PIPE READING |
|
902 |
||
903 |
typedef struct { |
|
1 | 904 |
lua_State *L; |
905 |
FILE *fd; |
|
906 |
int reference; |
|
0 | 907 |
} lua_bgread_callback_t; |
908 |
||
30
2cf24aced294
Definitions moved to cmake options
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
909 |
static gchar lua_bgread_buffer[MLUA_BGREAD_BUFFER]; |
0 | 910 |
|
911 |
static void lua_bgread_callback_destroy (lua_bgread_callback_t *cb) |
|
912 |
{ |
|
1 | 913 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
914 |
pclose (cb->fd); |
|
915 |
luaL_free (cb->L, cb); |
|
0 | 916 |
} |
917 |
||
918 |
/// background reading function |
|
919 |
/// Function, that processes output from pipe in asynchroneous way. |
|
920 |
/// A: string (data) or nil (eof) |
|
921 |
/// R: boolean (false if reading should be terminated) |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
922 |
static gboolean lua_bgread_callback (GIOChannel *source, GIOCondition condition, lua_bgread_callback_t *cb) |
0 | 923 |
{ |
1 | 924 |
int ret = TRUE; |
0 | 925 |
|
1 | 926 |
if (condition | G_IO_IN) { // data |
927 |
while (TRUE) { |
|
928 |
gsize read = 0; |
|
30
2cf24aced294
Definitions moved to cmake options
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
929 |
g_io_channel_read_chars (source, lua_bgread_buffer, MLUA_BGREAD_BUFFER, &read, NULL); |
1 | 930 |
if (!read) // exausted |
931 |
break; |
|
0 | 932 |
|
1 | 933 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
934 |
lua_pushlstring (cb->L, lua_bgread_buffer, read); |
|
935 |
if (lua_pcall (cb->L, 1, 1, 0)) { |
|
936 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Bgread callback execution error: %s", lua_tostring (cb->L, -1)); |
|
937 |
lua_pop (cb->L, 1); |
|
938 |
return FALSE; |
|
939 |
} |
|
940 |
ret = lua_toboolean (cb->L, -1); |
|
941 |
lua_pop (cb->L, 1); |
|
942 |
if (!ret) // enough |
|
943 |
return FALSE; |
|
944 |
} |
|
945 |
} |
|
0 | 946 |
|
1 | 947 |
if (condition & ~G_IO_IN) { // err or hup |
948 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
|
949 |
lua_pushnil (cb->L); |
|
950 |
if (lua_pcall (cb->L, 1, 1, 0)) { |
|
951 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Bgread callback execution error: %s", lua_tostring (cb->L, -1)); |
|
952 |
lua_pop (cb->L, 1); |
|
953 |
return FALSE; |
|
954 |
} |
|
955 |
ret = lua_toboolean (cb->L, -1); |
|
956 |
lua_pop (cb->L, 1); |
|
957 |
} |
|
0 | 958 |
|
1 | 959 |
return ret; |
0 | 960 |
} |
961 |
||
962 |
/// main.bgread |
|
1 | 963 |
/// Runs specified command and passes its output to a given function. |
0 | 964 |
/// A: string (command), background reading function |
965 |
static int lua_main_bgread (lua_State *L) |
|
966 |
{ |
|
1 | 967 |
const char *command = luaL_checkstring (L, 1); |
968 |
lua_bgread_callback_t *cb; |
|
969 |
FILE *fd; |
|
970 |
GIOChannel *channel; |
|
971 |
const char *charset = NULL; |
|
972 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
|
0 | 973 |
|
1 | 974 |
fd = popen (command, "r"); |
975 |
if (!fd) { |
|
976 |
lua_pushstring (L, "Error opening pipe"); |
|
977 |
lua_error (L); |
|
978 |
} |
|
0 | 979 |
|
1 | 980 |
channel = g_io_channel_unix_new (fileno (fd)); |
981 |
// We, most likely, need this, |
|
982 |
// But we cannot use this, |
|
983 |
// It will block. |
|
984 |
//if (!g_get_charset (&charset)) |
|
985 |
g_io_channel_set_encoding (channel, charset, NULL); |
|
986 |
g_io_channel_set_buffered (channel, FALSE); |
|
987 |
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); |
|
988 |
g_io_channel_set_close_on_unref (channel, TRUE); |
|
0 | 989 |
|
1 | 990 |
cb = luaL_malloc (L, sizeof (lua_bgread_callback_t)); |
991 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
|
992 |
cb->L = L; |
|
993 |
cb->fd = fd; |
|
0 | 994 |
|
30
2cf24aced294
Definitions moved to cmake options
Myhailo Danylenko <isbear@ukrpost.net>
parents:
29
diff
changeset
|
995 |
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); |
1 | 996 |
return 0; |
0 | 997 |
} |
998 |
||
999 |
// MAIN INITIALIZATION CODE |
|
1000 |
||
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1001 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1002 |
// FIXME: this should not be here |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1003 |
guint lua_lm_log_handler_id; |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1004 |
|
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1005 |
void lua_lm_log_handler (const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer ignore) |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1006 |
{ |
29 | 1007 |
if (settings_opt_get_int ("lua_lm_debug")) |
1008 |
scr_LogPrint (LPRINT_LOGNORM, "%s: %s", domain, message); |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1009 |
} |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1010 |
#endif |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1011 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1012 |
static void do_lua(char *arg, lua_State *L) |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1013 |
{ |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1014 |
if (luaL_loadbuffer (L, arg, strlen (arg), "line")) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1015 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Compilation error: %s", lua_tostring (L, -1)); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1016 |
lua_pop (L, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1017 |
return; |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1018 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1019 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1020 |
if (lua_pcall (L, 0, 0, 0)) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1021 |
scr_LogPrint (LPRINT_NORMAL, "lua: Runtime error: %s", lua_tostring(lua, -1)); |
8 | 1022 |
lua_pop (L, 1); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1023 |
return; |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1024 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1025 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1026 |
|
0 | 1027 |
static void lua_hook (hk_arg_t *args, lua_State *L) |
1028 |
{ |
|
40 | 1029 |
hk_arg_t *arg = args; |
6 | 1030 |
const char *hook = settings_opt_get ("lua_hook_function"); |
1031 |
if (!hook) |
|
1032 |
return; |
|
1033 |
lua_getglobal (lua, hook); |
|
1 | 1034 |
if (!lua_isfunction (lua, -1)) { |
1035 |
lua_pop (lua, 1); |
|
1036 |
return; |
|
1037 |
} |
|
1038 |
lua_newtable (L); |
|
1039 |
while (arg->name != NULL) { |
|
13 | 1040 |
char *name = from_utf8 (arg->name); |
1041 |
char *value = from_utf8 (arg->value); |
|
1042 |
lua_pushstring (L, name); |
|
1043 |
lua_pushstring (L, value); |
|
1 | 1044 |
lua_settable (L, -3); |
13 | 1045 |
g_free (name); |
1046 |
g_free (value); |
|
1 | 1047 |
arg++; |
1048 |
} |
|
1049 |
if (lua_pcall (lua, 1, 0, 0)) { |
|
6 | 1050 |
scr_LogPrint (LPRINT_NORMAL, "lua: Error in hook handler: %s", lua_tostring (lua, -1)); |
1 | 1051 |
lua_pop (lua, 1); |
1052 |
} |
|
1053 |
} |
|
1054 |
||
1055 |
static void *lua_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
|
1056 |
if (nsize == 0) { |
|
1057 |
g_free (ptr); |
|
1058 |
return NULL; |
|
1059 |
} else |
|
1060 |
return g_realloc (ptr, nsize); |
|
0 | 1061 |
} |
1062 |
||
10 | 1063 |
#define reg(NAME) \ |
1064 |
{ #NAME, lua_main_##NAME }, |
|
0 | 1065 |
static const luaL_Reg lua_reg_main[] = { |
40 | 1066 |
reg ( yesno ) |
1067 |
reg ( connection ) |
|
1068 |
reg ( log ) |
|
1069 |
reg ( option ) |
|
1070 |
reg ( alias ) |
|
1071 |
reg ( binding ) |
|
1072 |
reg ( fileoption ) |
|
1073 |
reg ( add_feature ) |
|
1074 |
reg ( del_feature ) |
|
1075 |
reg ( parse_args ) |
|
1076 |
reg ( add_category ) |
|
1077 |
reg ( del_category ) |
|
1078 |
reg ( add_completion ) |
|
1079 |
reg ( del_completion ) |
|
1080 |
reg ( command ) |
|
1081 |
reg ( print_info ) |
|
1082 |
reg ( beep ) |
|
1083 |
reg ( run ) |
|
1084 |
reg ( status ) |
|
1085 |
reg ( roster ) |
|
1086 |
reg ( current_buddy ) |
|
1087 |
reg ( full_jid ) |
|
1088 |
reg ( buddy_info ) |
|
1089 |
reg ( timer ) |
|
1090 |
reg ( bgread ) |
|
10 | 1091 |
{ NULL, NULL }, |
0 | 1092 |
}; |
10 | 1093 |
#undef reg |
1094 |
||
0 | 1095 |
const gchar *g_module_check_init (GModule *module) |
1096 |
{ |
|
1 | 1097 |
lua = lua_newstate (lua_alloc, NULL); |
1098 |
if (!lua) { |
|
1099 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Initialization error"); |
|
1100 |
return "Lua initialization error"; |
|
1101 |
} |
|
0 | 1102 |
|
1 | 1103 |
luaL_openlibs (lua); |
0 | 1104 |
|
1 | 1105 |
luaL_register (lua, "main", lua_reg_main); |
1106 |
lua_pop (lua, 1); // XXX |
|
1107 |
lua_register (lua, "dopath", lua_global_dopath); |
|
1108 |
lua_register (lua, "print", lua_global_print ); |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1109 |
|
32
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1110 |
{ |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1111 |
int cid = compl_new_category (); |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1112 |
|
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1113 |
if (cid) { |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1114 |
const string2enum_t *word = lua_yesno; |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1115 |
lua_completion_type[MLUA_YESNO_POS].value = cid; |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1116 |
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
|
1117 |
while (word->string) { |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1118 |
compl_add_category_word (cid, word->string); |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1119 |
++word; |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1120 |
} |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1121 |
} |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1122 |
} |
524fde5be49a
Yesno completion in C
Myhailo Danylenko <isbear@ukrpost.net>
parents:
31
diff
changeset
|
1123 |
|
11 | 1124 |
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
|
1125 |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1126 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1127 |
// FIXME: this should not be here. |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1128 |
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
|
1129 |
#endif |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1130 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1131 |
#if 1 |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1132 |
{ |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1133 |
char *initfile = expand_filename (settings_opt_get ("lua_init_filename")); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1134 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1135 |
if (!initfile) |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1136 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Cannot determine config file name"); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1137 |
else { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1138 |
if (luaL_loadfile(lua, initfile)) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1139 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Unable to compile rc file: %s", lua_tostring (lua, -1)); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1140 |
lua_pop (lua, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1141 |
} else if (lua_pcall (lua, 0, LUA_MULTRET, 0)) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1142 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Runtime error in rc file: %s", lua_tostring(lua, -1)); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1143 |
lua_pop (lua, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1144 |
} else |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1145 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Loaded %s", initfile); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1146 |
g_free (initfile); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1147 |
} |
1 | 1148 |
} |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1149 |
#endif |
0 | 1150 |
|
1 | 1151 |
hk_add_handler ((hk_handler_t) lua_hook, lua); |
0 | 1152 |
|
6 | 1153 |
{ |
1154 |
hk_arg_t args[] = { |
|
1155 |
{ "hook", "hook-start" }, |
|
1156 |
{ NULL, NULL }, |
|
1157 |
}; |
|
1158 |
lua_hook (args, lua); |
|
1 | 1159 |
} |
6 | 1160 |
|
1 | 1161 |
return NULL; |
0 | 1162 |
} |
1163 |
||
29 | 1164 |
static void lua_timers_destroy (guint source, gpointer ignore) |
1165 |
{ |
|
1166 |
g_source_remove (source); |
|
1167 |
} |
|
1168 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1169 |
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
|
1170 |
{ |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1171 |
xmpp_del_feature (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1172 |
g_free (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1173 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1174 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1175 |
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
|
1176 |
{ |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1177 |
lua_command_callback_t *cb = cmd_del (name); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1178 |
if (cb) { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1179 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1180 |
luaL_free (cb->L, cb); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1181 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1182 |
g_free (name); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1183 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1184 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1185 |
static void lua_categories_destroy (guint id, gpointer ignore) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1186 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1187 |
compl_del_category (id); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1188 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1189 |
|
0 | 1190 |
void g_module_unload (GModule *module) |
1191 |
{ |
|
1 | 1192 |
if (lua) { |
6 | 1193 |
hk_arg_t args[] = { |
1194 |
{ "hook", "hook-quit" }, |
|
1195 |
{ NULL, NULL }, |
|
1196 |
}; |
|
1197 |
lua_hook (args, lua); |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1198 |
|
1 | 1199 |
hk_del_handler ((hk_handler_t) lua_hook, lua); |
0 | 1200 |
|
29 | 1201 |
g_slist_foreach (lua_timers, (GFunc) lua_timers_destroy, NULL); |
1202 |
g_slist_free (lua_timers); |
|
1203 |
lua_timers = NULL; |
|
1204 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1205 |
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
|
1206 |
g_slist_free (lua_added_features); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1207 |
lua_added_features = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1208 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1209 |
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
|
1210 |
g_slist_free (lua_added_commands); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1211 |
lua_added_commands = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1212 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1213 |
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
|
1214 |
g_slist_free (lua_added_categories); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1215 |
lua_added_categories = NULL; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1216 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1217 |
cmd_del ("lua"); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1218 |
|
1 | 1219 |
lua_close (lua); |
1220 |
lua = NULL; |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1221 |
|
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1222 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1223 |
// FIXME: shouldn't be here |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1224 |
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
|
1225 |
#endif |
1 | 1226 |
} |
0 | 1227 |
} |
1228 |