author | Myhailo Danylenko <isbear@ukrpost.net> |
Tue, 03 Mar 2009 23:20:29 +0200 | |
changeset 15 | b224cbc7b8be |
parent 14 | ff13ba17fb6d |
child 17 | 3a12759a22b1 |
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 |
0 | 30 |
char *mcabber_config_filename (const char *file) |
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; |
1 | 59 |
if (!strncmp (name + size - 4, ".lua", 4)) |
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 |
||
79 |
/// main.config_file |
|
80 |
/// Adds mcabber default config location path to config file name. |
|
1 | 81 |
/// Note: deprecated, use dopath. |
13 | 82 |
/// XXX: should we use g_filename_from_utf8? |
0 | 83 |
/// A: string (filename) |
84 |
/// R: string (full path) |
|
85 |
static int lua_main_config_file (lua_State *L) |
|
86 |
{ |
|
1 | 87 |
char *home = mcabber_config_filename (luaL_checkstring (L, 1)); |
88 |
if (!home) { |
|
89 |
lua_pushstring (L, "Cannot find home dir!"); |
|
90 |
lua_error (L); |
|
91 |
} |
|
92 |
lua_pushstring (L, home); |
|
93 |
g_free (home); |
|
94 |
return 1; |
|
0 | 95 |
} |
96 |
||
97 |
/// log print type |
|
1 | 98 |
/// G: |
0 | 99 |
static const string2enum_t lua_lprint[] = { |
1 | 100 |
{ "normal", LPRINT_NORMAL }, |
101 |
{ "log", LPRINT_LOG }, |
|
102 |
{ "debug", LPRINT_DEBUG }, |
|
103 |
{ "notutf0", LPRINT_NOTUTF8 }, |
|
104 |
{ NULL, 0 }, |
|
0 | 105 |
}; |
106 |
||
1 | 107 |
/// roster type |
108 |
/// G: |
|
0 | 109 |
static const string2enum_t lua_roster_type[] = { |
1 | 110 |
{ "user", ROSTER_TYPE_USER }, |
111 |
{ "group", ROSTER_TYPE_GROUP }, |
|
112 |
{ "agent", ROSTER_TYPE_AGENT }, |
|
113 |
{ "room", ROSTER_TYPE_ROOM }, |
|
114 |
{ "special", ROSTER_TYPE_SPECIAL }, |
|
115 |
{ NULL, 0 }, |
|
0 | 116 |
}; |
117 |
||
118 |
/// main.log |
|
119 |
/// Prints message to log. |
|
13 | 120 |
/// Note: most likely you need notutf8 flag enabled. |
0 | 121 |
/// A: log print type, message, message... |
122 |
static int lua_main_log (lua_State *L) |
|
123 |
{ |
|
1 | 124 |
int type = luaL_checkenum_multi (L, 1, lua_lprint); |
125 |
lua_concat (L, lua_gettop (L) - 1); |
|
126 |
scr_LogPrint (type, lua_tostring (L, -1)); |
|
127 |
return 0; |
|
0 | 128 |
} |
129 |
||
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
130 |
// expects table on top |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
131 |
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
|
132 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
133 |
char *loc = from_utf8 (key); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
134 |
lua_pushstring (L, loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
135 |
g_free (loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
136 |
loc = from_utf8 (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
137 |
lua_pushstring (L, loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
138 |
g_free (loc); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
139 |
lua_settable (L, -3); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
140 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
141 |
|
0 | 142 |
/// main.option |
143 |
/// Sets or gets value of mcabber option. |
|
144 |
/// 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
|
145 |
/// 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
|
146 |
/// A: string (option name, optional), string (value, optional) |
0 | 147 |
/// R: string (value, optional) |
148 |
static int lua_main_option (lua_State *L) |
|
149 |
{ |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
150 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
151 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
152 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
153 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
154 |
if (lua_type (L, 2) == LUA_TNIL) // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
155 |
settings_del (SETTINGS_TYPE_OPTION, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
156 |
else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
157 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
158 |
settings_set (SETTINGS_TYPE_OPTION, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
159 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
160 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
161 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
162 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
163 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
164 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_OPTION, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
165 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
166 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
167 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
168 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
169 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
170 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
171 |
return 1; |
1 | 172 |
} |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
173 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
174 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
175 |
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
|
176 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
177 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
178 |
} |
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 |
/// main.alias |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
181 |
/// Sets or gets alias. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
182 |
/// You can specify nil as a command to delete alias. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
183 |
/// 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
|
184 |
/// A: string (alias name, optional), string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
185 |
/// R: string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
186 |
static int lua_main_alias (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
187 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
188 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
189 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
190 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
191 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
192 |
if (lua_type (L, 2) == LUA_TNIL) { // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
193 |
settings_del (SETTINGS_TYPE_ALIAS, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
194 |
compl_del_category_word (COMPL_CMD, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
195 |
} else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
196 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
197 |
if (!settings_get (SETTINGS_TYPE_ALIAS, name)) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
198 |
compl_add_category_word (COMPL_CMD, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
199 |
settings_set (SETTINGS_TYPE_ALIAS, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
200 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
201 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
202 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
203 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
204 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
205 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_ALIAS, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
206 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
207 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
208 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
209 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
210 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
211 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
212 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
213 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
214 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
215 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
216 |
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
|
217 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
218 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
219 |
} |
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 |
/// main.bind |
15 | 222 |
/// Sets or gets binding. |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
223 |
/// You can specify nil as a command to unbind key. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
224 |
/// 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
|
225 |
/// A: string (keycode, optional), string (command, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
226 |
/// R: string (command, optional) |
15 | 227 |
static int lua_main_binding (lua_State *L) |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
228 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
229 |
int top = lua_gettop (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
230 |
if (top > 0) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
231 |
// just to be sure... |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
232 |
char *name = to_utf8 (luaL_checkstring (L, 1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
233 |
if (top > 1) { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
234 |
if (lua_type (L, 2) == LUA_TNIL) // Unset |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
235 |
settings_del (SETTINGS_TYPE_BINDING, name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
236 |
else { // Set |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
237 |
char *value = to_utf8 (luaL_checkstring (L, 2)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
238 |
settings_set (SETTINGS_TYPE_BINDING, name, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
239 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
240 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
241 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
242 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
243 |
} else { // Get |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
244 |
char *value = from_utf8 (settings_get (SETTINGS_TYPE_BINDING, name)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
245 |
if (value) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
246 |
lua_pushstring (L, value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
247 |
g_free (value); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
248 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
249 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
250 |
g_free (name); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
251 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
252 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
253 |
} else { // List |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
254 |
lua_newtable (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
255 |
settings_foreach (SETTINGS_TYPE_BINDING, (void (*)(char *key, char *val, void *ud)) lua_options_callback, L); |
1 | 256 |
return 1; |
257 |
} |
|
0 | 258 |
} |
259 |
||
260 |
/// main.connection |
|
261 |
/// Returns lightuserdata of mcabber's loudmouth connection. |
|
262 |
/// This can be very useful with lua-loudmouth, and not much otherwise. |
|
263 |
/// R: lightuserdata |
|
264 |
static int lua_main_connection (lua_State *L) |
|
265 |
{ |
|
1 | 266 |
lua_pushlightuserdata (L, lconnection); |
267 |
return 1; |
|
0 | 268 |
} |
269 |
||
270 |
/// main.print_info |
|
271 |
/// Prints a system message to buddy's window. |
|
272 |
/// A: string (jid), string (message) |
|
273 |
static int lua_main_print_info (lua_State *L) |
|
274 |
{ |
|
13 | 275 |
char *jid = to_utf8 (luaL_checkstring (L, 1)); |
276 |
char *to = jidtodisp (jid); |
|
277 |
char *mesg = to_utf8 (luaL_checkstring (L, 2)); |
|
278 |
scr_WriteIncomingMessage (to, mesg, 0, HBB_PREFIX_INFO, 0); |
|
279 |
g_free (mesg); |
|
1 | 280 |
g_free (to); |
13 | 281 |
g_free (jid); |
1 | 282 |
return 0; |
0 | 283 |
} |
284 |
||
285 |
/// main.beep |
|
286 |
/// Beeps with system speaker. |
|
287 |
static int lua_main_beep (lua_State *L) |
|
288 |
{ |
|
1 | 289 |
scr_Beep (); |
290 |
return 0; |
|
0 | 291 |
} |
292 |
||
293 |
/// main.run |
|
294 |
/// Runs specified mcabber command. |
|
295 |
/// A: string |
|
296 |
static int lua_main_run (lua_State *L) |
|
297 |
{ |
|
1 | 298 |
process_command (luaL_checkstring (L, 1), TRUE); |
299 |
return 0; |
|
0 | 300 |
} |
301 |
||
302 |
/// main.status |
|
303 |
/// Returns your current status. |
|
1 | 304 |
/// R: string (status letter), string (status message) |
0 | 305 |
static int lua_main_status (lua_State *L) |
306 |
{ |
|
1 | 307 |
char *sm = from_utf8 (xmpp_getstatusmsg ()); |
308 |
lua_pushlstring (L, &imstatus2char[xmpp_getstatus ()], 1); |
|
309 |
lua_pushstring (L, sm); |
|
310 |
g_free (sm); |
|
311 |
return 2; |
|
0 | 312 |
} |
313 |
||
1 | 314 |
// expects table on top |
0 | 315 |
static void lua_rosterlist_callback (gpointer buddy, lua_State *L) |
316 |
{ |
|
13 | 317 |
char *jid = from_utf8 (buddy_getjid (buddy)); |
1 | 318 |
lua_pushnumber (L, lua_objlen (L, -1) + 1); |
13 | 319 |
lua_pushstring (L, jid); |
1 | 320 |
lua_settable (L, -3); |
13 | 321 |
g_free (jid); |
0 | 322 |
} |
323 |
||
324 |
/// main.roster |
|
325 |
/// Returns array of jids of buddies in roster. |
|
326 |
/// R: table |
|
327 |
static int lua_main_roster (lua_State *L) |
|
328 |
{ |
|
1 | 329 |
lua_newtable (L); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
330 |
foreach_buddy (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM, (void (*) (gpointer buddy, void *data)) lua_rosterlist_callback, L); |
1 | 331 |
return 1; |
0 | 332 |
} |
333 |
||
334 |
/// main.current_buddy |
|
10 | 335 |
/// Returns jid of current selected buddy or sets current buddy to buddy with specified jid. |
336 |
/// A: string (optional) |
|
337 |
/// R: string (optional) |
|
0 | 338 |
static int lua_main_current_buddy (lua_State *L) |
339 |
{ |
|
10 | 340 |
if (lua_gettop (L) > 0) { // Set |
13 | 341 |
// XXX: we need not convert to utf, RS works on jids/names in locale charset, |
342 |
// but will jidtodisp always correctly work on such tings? |
|
10 | 343 |
char *jid = jidtodisp (luaL_checkstring (L, 1)); |
344 |
scr_RosterSearch (jid); |
|
345 |
g_free (jid); |
|
346 |
return 0; |
|
347 |
} else { // Get |
|
13 | 348 |
char *jid = from_utf8 (buddy_getjid (BUDDATA (current_buddy))); |
349 |
lua_pushstring (L, jid); |
|
350 |
g_free (jid); |
|
10 | 351 |
return 1; |
352 |
} |
|
353 |
} |
|
354 |
||
355 |
/// main.full_jid |
|
356 |
/// Returns full jid (with current resource) of specified buddy (or current, if not specified). |
|
357 |
/// Note, that if there are no resources online, it will return just what it got. |
|
358 |
/// A: string (jid, optional) |
|
359 |
/// R: string (jid) |
|
360 |
static int lua_main_full_jid (lua_State *L) |
|
361 |
{ |
|
362 |
GList *buddy; |
|
363 |
GSList *resources; |
|
364 |
GSList *resource; |
|
13 | 365 |
if (lua_gettop (L) > 0) { |
366 |
char *jid = from_utf8 (luaL_checkstring (L, 1)); |
|
367 |
buddy = buddy_search_jid (jid); |
|
368 |
g_free (jid); |
|
369 |
} else |
|
10 | 370 |
buddy = current_buddy; |
371 |
if (!buddy) |
|
372 |
return 0; |
|
373 |
resources = buddy_getresources (BUDDATA (buddy)); |
|
374 |
if (!resources) { |
|
13 | 375 |
char *loc = from_utf8 (buddy_getjid (BUDDATA (buddy))); |
376 |
lua_pushstring (L, loc); |
|
377 |
g_free (loc); |
|
378 |
} else { |
|
379 |
char *jid = from_utf8 (buddy_getjid (BUDDATA (buddy))); |
|
380 |
char *res = from_utf8 (g_slist_last (resources)->data); |
|
381 |
lua_pushfstring (L, "%s%c%s", jid, JID_RESOURCE_SEPARATOR, res); |
|
382 |
for (resource = resources; resource; resource = g_slist_next (resource)) |
|
383 |
g_free (resource->data); |
|
384 |
g_slist_free (resources); |
|
385 |
g_free (jid); |
|
386 |
g_free (res); |
|
10 | 387 |
} |
1 | 388 |
return 1; |
0 | 389 |
} |
390 |
||
391 |
typedef struct { |
|
1 | 392 |
lua_State *L; |
393 |
gpointer buddy; |
|
0 | 394 |
} lua_state_and_buddy_t; // :) |
395 |
||
396 |
// expects table on top! |
|
397 |
static void lua_buddy_resources_callback (gpointer resource, lua_state_and_buddy_t *d) |
|
398 |
{ |
|
13 | 399 |
char *loc = from_utf8 (resource); |
400 |
lua_pushstring (d->L, loc); |
|
401 |
g_free (loc); |
|
1 | 402 |
lua_createtable (d->L, 0, 3); |
403 |
lua_pushstring (d->L, "priority"); |
|
404 |
lua_pushnumber (d->L, buddy_getresourceprio (d->buddy, resource)); |
|
405 |
lua_settable (d->L, -3); |
|
406 |
lua_pushstring (d->L, "status"); |
|
407 |
lua_pushlstring (d->L, &imstatus2char[buddy_getstatus (d->buddy, resource)], 1); |
|
408 |
lua_settable (d->L, -3); |
|
409 |
lua_pushstring (d->L, "message"); |
|
13 | 410 |
loc = from_utf8 (buddy_getstatusmsg (d->buddy, resource)); |
411 |
lua_pushstring (d->L, loc); |
|
412 |
g_free (loc); |
|
1 | 413 |
lua_settable (d->L, -3); |
414 |
lua_settable (d->L, -3); |
|
10 | 415 |
g_free (resource); |
0 | 416 |
} |
417 |
||
418 |
/// main.buddy_info |
|
419 |
/// Returns a hash table with information on specified buddy. |
|
420 |
/// Table contains fields type, name, onserver and resources. |
|
421 |
/// Resources is also a hash table, that contains tables with information, |
|
422 |
/// specific for each resource. In each resource table there are fields |
|
423 |
/// priority, status and message. |
|
424 |
/// A: string (jid) |
|
425 |
/// R: table |
|
426 |
static int lua_main_buddy_info (lua_State *L) |
|
427 |
{ |
|
13 | 428 |
char *loc = to_utf8 (luaL_checkstring (L, 1)); |
429 |
char *jid = jidtodisp (loc); |
|
1 | 430 |
GSList *buddy = roster_find (jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
10 | 431 |
GSList *resources; |
1 | 432 |
lua_state_and_buddy_t snb; |
433 |
g_free (jid); |
|
13 | 434 |
g_free (loc); |
1 | 435 |
|
436 |
if (!buddy) { |
|
437 |
lua_pushnil (L); |
|
438 |
return 1; |
|
439 |
} |
|
0 | 440 |
|
1 | 441 |
lua_createtable (L, 0, 3); |
442 |
lua_pushstring (L, "type"); |
|
443 |
luaL_pushenum (L, buddy_gettype (BUDDATA (buddy)), lua_roster_type); |
|
444 |
lua_settable (L, -3); |
|
445 |
lua_pushstring (L, "name"); |
|
13 | 446 |
loc = from_utf8 (buddy_getname (BUDDATA (buddy))); |
447 |
lua_pushstring (L, loc); |
|
448 |
g_free (loc); |
|
1 | 449 |
lua_settable (L, -3); |
450 |
lua_pushstring (L, "onserver"); |
|
451 |
lua_pushboolean (L, buddy_getonserverflag (BUDDATA (buddy))); |
|
452 |
lua_settable (L, -3); |
|
453 |
lua_pushstring (L, "resources"); |
|
454 |
lua_createtable (L, 0, 0); |
|
455 |
snb.L = L; |
|
456 |
snb.buddy = BUDDATA (buddy); |
|
10 | 457 |
resources = buddy_getresources (BUDDATA (buddy)); |
1 | 458 |
g_slist_foreach (buddy_getresources (BUDDATA (buddy)), (GFunc) lua_buddy_resources_callback, &snb); |
10 | 459 |
g_slist_free (resources); |
460 |
lua_settable (L, -3); |
|
1 | 461 |
|
462 |
return 1; |
|
0 | 463 |
} |
464 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
465 |
// XMPP DISCO FEATURES |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
466 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
467 |
GSList *lua_added_features = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
468 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
469 |
/// main.add_feature |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
470 |
/// Adds xmlns to disco#info features list. |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
471 |
/// A: string (xmlns) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
472 |
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
|
473 |
{ |
13 | 474 |
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
|
475 |
xmpp_add_feature (xmlns); |
13 | 476 |
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
|
477 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
478 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
479 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
480 |
/// main.del_feature |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
481 |
/// Removes xmlns from disco#info features list. |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
482 |
/// A: stirng (xmlns) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
483 |
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
|
484 |
{ |
13 | 485 |
char *xmlns = to_utf8 (luaL_checkstring (L, 1)); |
486 |
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
|
487 |
xmpp_del_feature (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
488 |
if (el) { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
489 |
g_free (el->data); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
490 |
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
|
491 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
492 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
493 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
494 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
495 |
// MCABBER COMMANDS |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
496 |
|
9 | 497 |
/// completion type |
498 |
/// Built-it completion types can be specified as string, instead of id. |
|
499 |
/// G: |
|
500 |
static const string2enum_t lua_completion_type[] = { |
|
501 |
{ "cmd", COMPL_CMD }, |
|
502 |
{ "jid", COMPL_JID }, |
|
503 |
{ "urljid", COMPL_URLJID }, |
|
504 |
{ "name", COMPL_NAME }, |
|
505 |
{ "status", COMPL_STATUS }, |
|
506 |
{ "filename", COMPL_FILENAME }, |
|
507 |
{ "roster", COMPL_ROSTER }, |
|
508 |
{ "buffer", COMPL_BUFFER }, |
|
509 |
{ "group", COMPL_GROUP }, |
|
510 |
{ "groupname", COMPL_GROUPNAME }, |
|
511 |
{ "multiline", COMPL_MULTILINE }, |
|
512 |
{ "room", COMPL_ROOM }, |
|
513 |
{ "resource", COMPL_RESOURCE }, |
|
514 |
{ "auth", COMPL_AUTH }, |
|
515 |
{ "request", COMPL_REQUEST }, |
|
516 |
{ "events", COMPL_EVENTS }, |
|
517 |
{ "eventsid", COMPL_EVENTSID }, |
|
518 |
{ "pgp", COMPL_PGP }, |
|
519 |
{ "color", COMPL_COLOR }, |
|
520 |
{ "otr", COMPL_OTR }, |
|
521 |
{ "ortpolicy", COMPL_OTRPOLICY }, |
|
522 |
{ NULL, 0 }, |
|
523 |
}; |
|
524 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
525 |
typedef struct { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
526 |
int reference; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
527 |
lua_State *L; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
528 |
} lua_command_callback_t; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
529 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
530 |
static GSList *lua_added_commands = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
531 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
532 |
static GSList *lua_added_categories = NULL; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
533 |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
534 |
/// command function |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
535 |
/// Function to handle newly registered command. |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
536 |
/// A: string (arguments) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
537 |
void lua_main_command_handler (char *args, lua_command_callback_t *cb) |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
538 |
{ |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
539 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
540 |
lua_pushstring (cb->L, args); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
541 |
if (lua_pcall (cb->L, 1, 0, 0)) { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
542 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Command execution error: %s", lua_tostring (cb->L, -1)); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
543 |
lua_pop (cb->L, 1); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
544 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
545 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
546 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
547 |
/// main.add_category |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
548 |
/// Adds completion category. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
549 |
/// A: table (values are used as words for completion, optional) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
550 |
/// R: integer (category id, in fact completion type) or nil |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
551 |
static int lua_main_add_category (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
552 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
553 |
guint cid; |
15 | 554 |
if (lua_gettop (L) > 0) { |
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
555 |
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
|
556 |
cid = compl_new_category (); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
557 |
if (cid) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
558 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
559 |
while (lua_next (L, 3)) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
560 |
char *word = to_utf8 (luaL_checkstring (L, -1)); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
561 |
if (word) { |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
562 |
compl_add_category_word (cid, word); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
563 |
g_free (word); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
564 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
565 |
lua_pop (L, 1); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
566 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
567 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
568 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
569 |
cid = compl_new_category (); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
570 |
if (cid) { |
15 | 571 |
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
|
572 |
lua_pushinteger (L, cid); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
573 |
} else |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
574 |
lua_pushnil (L); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
575 |
return 1; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
576 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
577 |
|
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
578 |
/// main.del_category |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
579 |
/// Removes completion category. |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
580 |
/// A: integer (category id) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
581 |
static int lua_main_del_category (lua_State *L) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
582 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
583 |
guint cid = luaL_checkinteger (L, 1); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
584 |
compl_del_category (cid); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
585 |
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
|
586 |
return 0; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
587 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
588 |
|
8 | 589 |
/// main.add_completion |
590 |
/// Adds word to a completion list. |
|
591 |
/// A: integer (completion group id), string (word) |
|
592 |
static int lua_main_add_completion (lua_State *L) |
|
593 |
{ |
|
13 | 594 |
guint cid = luaL_checkinteger (L, 1); |
595 |
char *word = to_utf8 (luaL_checkstring (L, 2)); // XXX |
|
8 | 596 |
compl_add_category_word (cid, word); |
13 | 597 |
g_free (word); |
8 | 598 |
} |
599 |
||
600 |
/// main.del_completion |
|
601 |
/// Removes word from a completion list. |
|
602 |
/// A: integer (completion group id), string (word) |
|
603 |
static int lua_main_del_completion (lua_State *L) |
|
604 |
{ |
|
13 | 605 |
guint cid = luaL_checkinteger (L, 1); |
606 |
char *word = to_utf8 (luaL_checkstring (L, 2)); // XXX |
|
8 | 607 |
compl_del_category_word (cid, word); |
13 | 608 |
g_free (word); |
8 | 609 |
} |
610 |
||
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
611 |
/// main.command |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
612 |
/// 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
|
613 |
/// To unregister command omit function argument. |
8 | 614 |
/// If you specify a third argument, table (even empty), function will return completion group id or nothing. |
9 | 615 |
/// You can also specify a string name (see completion type) instead of table, for non-builtin, you can just pass integer id. |
8 | 616 |
/// Note, that for now there are no way to unregister completion group, so, resources can be exausted easily. |
617 |
/// Also note, that it ignores keys in a completion table. |
|
9 | 618 |
/// A: string (command name), command function (optional), table (completions, optional)/completion type (or integer comletion group id, optional) |
619 |
/// 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
|
620 |
static int lua_main_command (lua_State *L) |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
621 |
{ |
13 | 622 |
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
|
623 |
lua_command_callback_t *cb; |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
624 |
if (lua_gettop (L) > 1) { // Register |
8 | 625 |
guint cid = 0; |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
626 |
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
|
627 |
|
8 | 628 |
if (lua_gettop (L) > 2) { // Completions provided |
629 |
if (lua_type (L, 3) == LUA_TTABLE) { |
|
630 |
cid = compl_new_category (); |
|
631 |
if (cid) { |
|
15 | 632 |
lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) cid); |
8 | 633 |
lua_pushnil (L); |
634 |
while (lua_next (L, 3)) { |
|
13 | 635 |
char *word = to_utf8 (luaL_checkstring (L, -1)); |
636 |
compl_add_category_word (cid, word); |
|
8 | 637 |
lua_pop (L, 1); |
13 | 638 |
g_free (word); |
8 | 639 |
} |
640 |
} |
|
641 |
} else |
|
9 | 642 |
cid = luaL_checkenum (L, 3, lua_completion_type); |
8 | 643 |
} |
644 |
||
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
645 |
cb = luaL_malloc (L, sizeof (lua_command_callback_t)); |
8 | 646 |
lua_pushvalue (L, 2); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
647 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
648 |
cb->L = L; |
8 | 649 |
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
|
650 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
651 |
lua_added_commands = g_slist_prepend (lua_added_commands, g_strdup (name)); |
8 | 652 |
|
653 |
if (cid) { |
|
9 | 654 |
luaL_pushenum (L, cid, lua_completion_type); |
8 | 655 |
return 1; |
656 |
} |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
657 |
} else { // Unregister |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
658 |
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
|
659 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
660 |
cb = cmd_del (name); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
661 |
if (cb) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
662 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
663 |
luaL_free (cb->L, cb); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
664 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
665 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
666 |
if (el) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
667 |
g_free (el->data); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
668 |
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
|
669 |
} |
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
670 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
671 |
return 0; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
672 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
673 |
|
0 | 674 |
// TIMER |
675 |
||
676 |
#define LUA_TIMER_PRIORITY ( G_PRIORITY_HIGH_IDLE ) |
|
677 |
||
678 |
typedef struct { |
|
1 | 679 |
int reference; |
680 |
lua_State *L; |
|
0 | 681 |
} lua_timer_callback_t; |
682 |
||
683 |
static void lua_timer_callback_destroy (lua_timer_callback_t *cb) |
|
684 |
{ |
|
1 | 685 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
686 |
luaL_free (cb->L, cb); |
|
0 | 687 |
} |
688 |
||
689 |
/// timer function |
|
690 |
/// Function, that will be called periodically until it returns false. |
|
691 |
/// R: boolean |
|
692 |
static gboolean lua_timer_callback (lua_timer_callback_t *cb) |
|
693 |
{ |
|
1 | 694 |
int ret; |
695 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
|
696 |
if (lua_pcall (cb->L, 0, 1, 0)) { |
|
697 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Timer callback execution error: %s", lua_tostring (cb->L, -1)); |
|
698 |
lua_pop (cb->L, 1); |
|
699 |
return FALSE; |
|
700 |
} |
|
701 |
ret = lua_toboolean (cb->L, -1); |
|
702 |
lua_pop (cb->L, 1); |
|
703 |
return ret; |
|
0 | 704 |
} |
705 |
||
706 |
/// main.timer |
|
707 |
/// Creates new timer function, that will be called periodically. |
|
708 |
/// A: integer (interval, seconds), timer function |
|
709 |
static int lua_main_timer (lua_State *L) |
|
710 |
{ |
|
1 | 711 |
int interval = luaL_checkint (L, 1); |
712 |
lua_timer_callback_t *cb; |
|
713 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
|
0 | 714 |
|
1 | 715 |
cb = luaL_malloc (L, sizeof (lua_timer_callback_t)); |
716 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
|
717 |
cb->L = L; |
|
0 | 718 |
|
1 | 719 |
g_timeout_add_seconds_full (LUA_TIMER_PRIORITY, interval, (GSourceFunc) lua_timer_callback, cb, (GDestroyNotify) lua_timer_callback_destroy); |
720 |
return 0; |
|
0 | 721 |
} |
722 |
||
723 |
// BACKGROUND PIPE READING |
|
724 |
||
725 |
#define LUA_BGREAD_BUFFER ( 4096 ) |
|
726 |
||
727 |
typedef struct { |
|
1 | 728 |
lua_State *L; |
729 |
FILE *fd; |
|
730 |
int reference; |
|
0 | 731 |
} lua_bgread_callback_t; |
732 |
||
733 |
static gchar lua_bgread_buffer[LUA_BGREAD_BUFFER]; |
|
734 |
||
735 |
static void lua_bgread_callback_destroy (lua_bgread_callback_t *cb) |
|
736 |
{ |
|
1 | 737 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
738 |
pclose (cb->fd); |
|
739 |
luaL_free (cb->L, cb); |
|
0 | 740 |
} |
741 |
||
742 |
/// background reading function |
|
743 |
/// Function, that processes output from pipe in asynchroneous way. |
|
744 |
/// A: string (data) or nil (eof) |
|
745 |
/// R: boolean (false if reading should be terminated) |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
746 |
static gboolean lua_bgread_callback (GIOChannel *source, GIOCondition condition, lua_bgread_callback_t *cb) |
0 | 747 |
{ |
1 | 748 |
int ret = TRUE; |
0 | 749 |
|
1 | 750 |
if (condition | G_IO_IN) { // data |
751 |
while (TRUE) { |
|
752 |
gsize read = 0; |
|
753 |
g_io_channel_read_chars (source, lua_bgread_buffer, LUA_BGREAD_BUFFER, &read, NULL); |
|
754 |
if (!read) // exausted |
|
755 |
break; |
|
0 | 756 |
|
1 | 757 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
758 |
lua_pushlstring (cb->L, lua_bgread_buffer, read); |
|
759 |
if (lua_pcall (cb->L, 1, 1, 0)) { |
|
760 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Bgread callback execution error: %s", lua_tostring (cb->L, -1)); |
|
761 |
lua_pop (cb->L, 1); |
|
762 |
return FALSE; |
|
763 |
} |
|
764 |
ret = lua_toboolean (cb->L, -1); |
|
765 |
lua_pop (cb->L, 1); |
|
766 |
if (!ret) // enough |
|
767 |
return FALSE; |
|
768 |
} |
|
769 |
} |
|
0 | 770 |
|
1 | 771 |
if (condition & ~G_IO_IN) { // err or hup |
772 |
lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference); |
|
773 |
lua_pushnil (cb->L); |
|
774 |
if (lua_pcall (cb->L, 1, 1, 0)) { |
|
775 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Bgread callback execution error: %s", lua_tostring (cb->L, -1)); |
|
776 |
lua_pop (cb->L, 1); |
|
777 |
return FALSE; |
|
778 |
} |
|
779 |
ret = lua_toboolean (cb->L, -1); |
|
780 |
lua_pop (cb->L, 1); |
|
781 |
} |
|
0 | 782 |
|
1 | 783 |
return ret; |
0 | 784 |
} |
785 |
||
786 |
/// main.bgread |
|
1 | 787 |
/// Runs specified command and passes its output to a given function. |
0 | 788 |
/// A: string (command), background reading function |
789 |
static int lua_main_bgread (lua_State *L) |
|
790 |
{ |
|
1 | 791 |
const char *command = luaL_checkstring (L, 1); |
792 |
lua_bgread_callback_t *cb; |
|
793 |
FILE *fd; |
|
794 |
GIOChannel *channel; |
|
795 |
const char *charset = NULL; |
|
796 |
luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
|
0 | 797 |
|
1 | 798 |
fd = popen (command, "r"); |
799 |
if (!fd) { |
|
800 |
lua_pushstring (L, "Error opening pipe"); |
|
801 |
lua_error (L); |
|
802 |
} |
|
0 | 803 |
|
1 | 804 |
channel = g_io_channel_unix_new (fileno (fd)); |
805 |
// We, most likely, need this, |
|
806 |
// But we cannot use this, |
|
807 |
// It will block. |
|
808 |
//if (!g_get_charset (&charset)) |
|
809 |
g_io_channel_set_encoding (channel, charset, NULL); |
|
810 |
g_io_channel_set_buffered (channel, FALSE); |
|
811 |
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); |
|
812 |
g_io_channel_set_close_on_unref (channel, TRUE); |
|
0 | 813 |
|
1 | 814 |
cb = luaL_malloc (L, sizeof (lua_bgread_callback_t)); |
815 |
cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
|
816 |
cb->L = L; |
|
817 |
cb->fd = fd; |
|
0 | 818 |
|
1 | 819 |
g_io_add_watch_full (channel, G_PRIORITY_HIGH_IDLE, G_IO_IN|G_IO_HUP|G_IO_ERR, (GIOFunc) lua_bgread_callback, cb, (GDestroyNotify) lua_bgread_callback_destroy); |
820 |
return 0; |
|
0 | 821 |
} |
822 |
||
823 |
// MAIN INITIALIZATION CODE |
|
824 |
||
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
825 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
826 |
// FIXME: this should not be here |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
827 |
guint lua_lm_log_handler_id; |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
828 |
|
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
829 |
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
|
830 |
{ |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
831 |
scr_LogPrint (LPRINT_LOGNORM, "%s: %s", domain, message); |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
832 |
} |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
833 |
#endif |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
834 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
835 |
static void do_lua(char *arg, lua_State *L) |
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 |
if (luaL_loadbuffer (L, arg, strlen (arg), "line")) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
838 |
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
|
839 |
lua_pop (L, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
840 |
return; |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
841 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
842 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
843 |
if (lua_pcall (L, 0, 0, 0)) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
844 |
scr_LogPrint (LPRINT_NORMAL, "lua: Runtime error: %s", lua_tostring(lua, -1)); |
8 | 845 |
lua_pop (L, 1); |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
846 |
return; |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
847 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
848 |
} |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
849 |
|
0 | 850 |
static void lua_hook (hk_arg_t *args, lua_State *L) |
851 |
{ |
|
1 | 852 |
hk_arg_t *arg = args; |
6 | 853 |
const char *hook = settings_opt_get ("lua_hook_function"); |
854 |
if (!hook) |
|
855 |
return; |
|
856 |
lua_getglobal (lua, hook); |
|
1 | 857 |
if (!lua_isfunction (lua, -1)) { |
858 |
lua_pop (lua, 1); |
|
859 |
return; |
|
860 |
} |
|
861 |
lua_newtable (L); |
|
862 |
while (arg->name != NULL) { |
|
13 | 863 |
char *name = from_utf8 (arg->name); |
864 |
char *value = from_utf8 (arg->value); |
|
865 |
lua_pushstring (L, name); |
|
866 |
lua_pushstring (L, value); |
|
1 | 867 |
lua_settable (L, -3); |
13 | 868 |
g_free (name); |
869 |
g_free (value); |
|
1 | 870 |
arg++; |
871 |
} |
|
872 |
if (lua_pcall (lua, 1, 0, 0)) { |
|
6 | 873 |
scr_LogPrint (LPRINT_NORMAL, "lua: Error in hook handler: %s", lua_tostring (lua, -1)); |
1 | 874 |
lua_pop (lua, 1); |
875 |
} |
|
876 |
} |
|
877 |
||
878 |
static void *lua_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
|
879 |
if (nsize == 0) { |
|
880 |
g_free (ptr); |
|
881 |
return NULL; |
|
882 |
} else |
|
883 |
return g_realloc (ptr, nsize); |
|
0 | 884 |
} |
885 |
||
10 | 886 |
#define reg(NAME) \ |
887 |
{ #NAME, lua_main_##NAME }, |
|
0 | 888 |
static const luaL_Reg lua_reg_main[] = { |
10 | 889 |
reg ( config_file ) |
890 |
reg ( connection ) |
|
891 |
reg ( log ) |
|
892 |
reg ( option ) |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
893 |
reg ( alias ) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
894 |
reg ( binding ) |
10 | 895 |
reg ( add_feature ) |
896 |
reg ( del_feature ) |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
897 |
reg ( add_category ) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
898 |
reg ( del_category ) |
10 | 899 |
reg ( add_completion ) |
900 |
reg ( del_completion ) |
|
901 |
reg ( command ) |
|
902 |
reg ( print_info ) |
|
903 |
reg ( beep ) |
|
904 |
reg ( run ) |
|
905 |
reg ( status ) |
|
906 |
reg ( roster ) |
|
907 |
reg ( current_buddy ) |
|
908 |
reg ( full_jid ) |
|
909 |
reg ( buddy_info ) |
|
910 |
reg ( timer ) |
|
911 |
reg ( bgread ) |
|
912 |
{ NULL, NULL }, |
|
0 | 913 |
}; |
10 | 914 |
#undef reg |
915 |
||
0 | 916 |
const gchar *g_module_check_init (GModule *module) |
917 |
{ |
|
1 | 918 |
lua = lua_newstate (lua_alloc, NULL); |
919 |
if (!lua) { |
|
920 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Initialization error"); |
|
921 |
return "Lua initialization error"; |
|
922 |
} |
|
0 | 923 |
|
1 | 924 |
luaL_openlibs (lua); |
0 | 925 |
|
1 | 926 |
luaL_register (lua, "main", lua_reg_main); |
927 |
lua_pop (lua, 1); // XXX |
|
928 |
lua_register (lua, "dopath", lua_global_dopath); |
|
929 |
lua_register (lua, "print", lua_global_print ); |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
930 |
|
11 | 931 |
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
|
932 |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
933 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
934 |
// FIXME: this should not be here. |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
935 |
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
|
936 |
#endif |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
937 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
938 |
#if 1 |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
939 |
{ |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
940 |
char *initfile = expand_filename (settings_opt_get ("lua_init_filename")); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
941 |
|
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
942 |
if (!initfile) |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
943 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Cannot determine config file name"); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
944 |
else { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
945 |
if (luaL_loadfile(lua, initfile)) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
946 |
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
|
947 |
lua_pop (lua, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
948 |
} else if (lua_pcall (lua, 0, LUA_MULTRET, 0)) { |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
949 |
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
|
950 |
lua_pop (lua, 1); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
951 |
} else |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
952 |
scr_LogPrint (LPRINT_LOGNORM, "lua: Loaded %s", initfile); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
953 |
g_free (initfile); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
954 |
} |
1 | 955 |
} |
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
956 |
#endif |
0 | 957 |
|
1 | 958 |
hk_add_handler ((hk_handler_t) lua_hook, lua); |
0 | 959 |
|
6 | 960 |
{ |
961 |
hk_arg_t args[] = { |
|
962 |
{ "hook", "hook-start" }, |
|
963 |
{ NULL, NULL }, |
|
964 |
}; |
|
965 |
lua_hook (args, lua); |
|
1 | 966 |
} |
6 | 967 |
|
1 | 968 |
return NULL; |
0 | 969 |
} |
970 |
||
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
971 |
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
|
972 |
{ |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
973 |
xmpp_del_feature (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
974 |
g_free (xmlns); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
975 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
976 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
977 |
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
|
978 |
{ |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
979 |
lua_command_callback_t *cb = cmd_del (name); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
980 |
if (cb) { |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
981 |
luaL_unref (cb->L, LUA_REGISTRYINDEX, cb->reference); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
982 |
luaL_free (cb->L, cb); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
983 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
984 |
g_free (name); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
985 |
} |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
986 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
987 |
static void lua_categories_destroy (guint id, gpointer ignore) |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
988 |
{ |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
989 |
compl_del_category (id); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
990 |
} |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
991 |
|
0 | 992 |
void g_module_unload (GModule *module) |
993 |
{ |
|
1 | 994 |
if (lua) { |
6 | 995 |
hk_arg_t args[] = { |
996 |
{ "hook", "hook-quit" }, |
|
997 |
{ NULL, NULL }, |
|
998 |
}; |
|
999 |
lua_hook (args, lua); |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1000 |
|
1 | 1001 |
hk_del_handler ((hk_handler_t) lua_hook, lua); |
0 | 1002 |
|
2
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1003 |
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
|
1004 |
g_slist_free (lua_added_features); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1005 |
lua_added_features = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1006 |
|
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1007 |
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
|
1008 |
g_slist_free (lua_added_commands); |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1009 |
lua_added_commands = NULL; |
a88a395e6868
Delete commands and features on unloading
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1
diff
changeset
|
1010 |
|
14
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1011 |
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
|
1012 |
g_slist_free (lua_added_categories); |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1013 |
lua_added_categories = NULL; |
ff13ba17fb6d
Completion and settings improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
13
diff
changeset
|
1014 |
|
7
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1015 |
cmd_del ("lua"); |
eb6d89bf1fbf
Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents:
6
diff
changeset
|
1016 |
|
1 | 1017 |
lua_close (lua); |
1018 |
lua = NULL; |
|
3
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1019 |
|
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1020 |
#ifdef LLM_LOG_HANDLER |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1021 |
// FIXME: shouldn't be here |
a5f864d4207f
Fixes for build system
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2
diff
changeset
|
1022 |
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
|
1023 |
#endif |
1 | 1024 |
} |
0 | 1025 |
} |
1026 |