author | Myhailo Danylenko <isbear@ukrpost.net> |
Sat, 05 Mar 2016 18:36:28 +0200 | |
changeset 150 | c8514af9b449 |
parent 142 | 7e8f523b66af |
child 151 | 5d90caa7fb2c |
permissions | -rw-r--r-- |
129 | 1 |
|
2 |
[[!meta title="Documentation for Lua module for MCabber"]] |
|
3 |
||
4 |
[[!toc]] |
|
5 |
||
6 |
||
7 |
- - - |
|
8 |
||
130 | 9 |
<a name="Lua.for.mcabber"></a> |
10 |
## Lua for mcabber |
|
11 |
Module provides embedded lua environment with some accessors to |
|
12 |
mcabber functionality. |
|
13 |
||
14 |
<a name="Options"></a> |
|
15 |
### Options |
|
16 |
||
17 |
* lua_init_filename - lua script, that will be loaded at startup |
|
18 |
* lua_lm_debug - if lm log handler is enabled, this option controls, whether lm log messages are dropped or passed to mcabber logging facility |
|
19 |
||
134
d7ab555b9766
Add section header to docs
Myhailo Danylenko <isbear@ukrpost.net>
parents:
133
diff
changeset
|
20 |
<a name="Provided.lua.functions"></a> |
d7ab555b9766
Add section header to docs
Myhailo Danylenko <isbear@ukrpost.net>
parents:
133
diff
changeset
|
21 |
### Provided lua functions |
d7ab555b9766
Add section header to docs
Myhailo Danylenko <isbear@ukrpost.net>
parents:
133
diff
changeset
|
22 |
|
129 | 23 |
<a name="print"></a> |
130 | 24 |
|
129 | 25 |
Prints its arguments to log with default priority. |
26 |
**Arguments:** something, ... |
|
27 |
||
28 |
<a name="dopath"></a> |
|
29 |
### dopath |
|
30 |
Loads lua file from default location. |
|
31 |
XXX: g_filename_from_utf8? |
|
32 |
**Arguments:** string (filename, without ".lua") |
|
33 |
**Return values:** string (error message, optional) |
|
34 |
||
35 |
<a name="yes.or.no.ansvers"></a> |
|
36 |
### yes or no ansvers |
|
37 |
**Values:** 1, 0, enable, disable, true, false, on, off, yes, no |
|
38 |
||
39 |
<a name="main.yesno"></a> |
|
40 |
### main.yesno |
|
41 |
According to [yes or no ansvers](#yes.or.no.ansvers) returns true or false. |
|
42 |
If ansver is not recognized, returns nil. |
|
43 |
**Arguments:** anything (string expected) |
|
44 |
**Return values:** boolean or nil |
|
45 |
||
46 |
<a name="main.version"></a> |
|
47 |
### main.version |
|
48 |
Returns information about mcabber version |
|
49 |
**Return values:** table |
|
50 |
||
133 | 51 |
<a name="log.message.type"></a> |
52 |
### log message type |
|
53 |
**Values:** normal, log, debug, notutf8 |
|
129 | 54 |
|
55 |
<a name="roster.type"></a> |
|
56 |
### roster type |
|
57 |
**Values:** user, group, agent, room, special |
|
58 |
||
59 |
<a name="main.log"></a> |
|
60 |
### main.log |
|
61 |
Prints message to log. |
|
62 |
Note: most likely you need notutf8 flag enabled. |
|
133 | 63 |
**Arguments:** [log message type](#log.message.type), message, message... |
129 | 64 |
|
65 |
<a name="main.option"></a> |
|
66 |
### main.option |
|
67 |
Sets or gets value of mcabber option. |
|
68 |
You can specify nil as a value to delete option. |
|
69 |
If you omit option name, it returns hash table of all options. |
|
70 |
**Arguments:** string (option name, optional), string (value, optional) |
|
71 |
**Return values:** string (value, optional) |
|
72 |
||
73 |
<a name="main.alias"></a> |
|
74 |
### main.alias |
|
75 |
Sets or gets alias. |
|
76 |
You can specify nil as a command to delete alias. |
|
77 |
If you omit alias name, it will return hash table of all aliases. |
|
78 |
**Arguments:** string (alias name, optional), string (command, optional) |
|
79 |
**Return values:** string (command, optional) |
|
80 |
||
81 |
<a name="main.bind"></a> |
|
82 |
### main.bind |
|
83 |
Sets or gets binding. |
|
84 |
You can specify nil as a command to unbind key. |
|
85 |
If you omit keycode, it will return hash table of all bindings. |
|
86 |
**Arguments:** string (keycode, optional), string (command, optional) |
|
87 |
**Return values:** string (command, optional) |
|
88 |
||
89 |
<a name="main.fileoption"></a> |
|
90 |
### main.fileoption |
|
91 |
Gets option, expanding it as filename. |
|
92 |
**Arguments:** string (option name) |
|
93 |
**Return values:** string (expanded option value) or nil |
|
94 |
||
95 |
<a name="main.connection"></a> |
|
96 |
### main.connection |
|
97 |
Returns lightuserdata of mcabber's loudmouth connection. |
|
98 |
This can be very useful with lua-loudmouth, and not much otherwise. |
|
99 |
**Return values:** lightuserdata or nil |
|
100 |
||
101 |
<a name="main.print.info"></a> |
|
102 |
### main.print_info |
|
103 |
Prints a system message to buddy's window. |
|
104 |
**Arguments:** string (jid), string (message) |
|
105 |
||
106 |
<a name="main.beep"></a> |
|
107 |
### main.beep |
|
108 |
Beeps with system speaker. |
|
109 |
||
110 |
<a name="main.run"></a> |
|
111 |
### main.run |
|
112 |
Runs specified mcabber command. |
|
113 |
**Arguments:** string |
|
114 |
||
115 |
<a name="main.status"></a> |
|
116 |
### main.status |
|
117 |
Returns your current status. |
|
118 |
**Return values:** string (status letter), string (status message) |
|
119 |
||
120 |
<a name="main.roster"></a> |
|
121 |
### main.roster |
|
122 |
Returns array of jids of buddies in roster. |
|
123 |
**Return values:** table |
|
124 |
||
125 |
<a name="main.current.buddy"></a> |
|
126 |
### main.current_buddy |
|
127 |
Returns jid of current selected buddy or sets current buddy to buddy with specified jid. |
|
128 |
**Arguments:** string (optional) |
|
129 |
**Return values:** string (optional) |
|
130 |
||
131 |
<a name="main.full.jid"></a> |
|
132 |
### main.full_jid |
|
133 |
Returns full jid (with current resource) of specified buddy (or current, if not specified). |
|
134 |
Note, that if there are no resources online, it will return just what it got. |
|
135 |
**Arguments:** string (jid, optional) |
|
136 |
**Return values:** string (jid) |
|
137 |
||
138 |
<a name="resources.table"></a> |
|
139 |
### resources table |
|
140 |
Hash table with resource name as keys and another hash tables as values. |
|
141 |
Inner tables contain resource-specific information: priority, status and message. |
|
142 |
||
143 |
<a name="main.buddy.info"></a> |
|
144 |
### main.buddy_info |
|
145 |
Returns a hash table with information on specified buddy. |
|
146 |
Table contains fields type, name, onserver and resources (which points to [resources table](#resources.table)). |
|
147 |
**Arguments:** string (jid) |
|
148 |
**Return values:** table |
|
149 |
||
150 |
<a name="main.add.feature"></a> |
|
151 |
### main.add_feature |
|
152 |
Adds xmlns to disco#info features list. |
|
153 |
**Arguments:** string (xmlns) |
|
154 |
||
155 |
<a name="main.del.feature"></a> |
|
156 |
### main.del_feature |
|
157 |
Removes xmlns from disco#info features list. |
|
158 |
**Arguments:** stirng (xmlns) |
|
159 |
||
160 |
<a name="event.context"></a> |
|
161 |
### event context |
|
162 |
Enum, indicating what exactly caused [event function](#event.function) firing. |
|
163 |
**Values:** timeout, cancel, reject, accept |
|
164 |
||
165 |
<a name="event.function"></a> |
|
166 |
### event function |
|
167 |
Function to be called, when some event state change occurs |
|
168 |
**Arguments:** [event context](#event.context), string (event args) |
|
169 |
**Return values:** boolean (if event shoud be preserved) |
|
170 |
||
171 |
<a name="main.event"></a> |
|
172 |
### main.event |
|
173 |
Creates new event. If called without arguments, returns event id list. |
|
174 |
**Arguments:** [event function](#event.function) (optional), string (event id), string (description, optional), integer (expiration timeout, optional) |
|
175 |
**Return values:** string (event id) or nothing (creation error) or table (list of event names) |
|
176 |
||
177 |
<a name="completion.type"></a> |
|
178 |
### completion type |
|
179 |
Built-it completion types can be specified as string, instead of id. |
|
150 | 180 |
**Values:** cmd, jid, urljid, name, status, filename, roster, buffer, group, groupname, multiline, room, resource, auth, request, events, eventsid, pgp, color, otr, ortpolicy, module, carbons, yesno |
142
7e8f523b66af
Add completion sorting.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
138
diff
changeset
|
181 |
|
7e8f523b66af
Add completion sorting.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
138
diff
changeset
|
182 |
<a name="completion.sorting.order"></a> |
7e8f523b66af
Add completion sorting.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
138
diff
changeset
|
183 |
### completion sorting order |
7e8f523b66af
Add completion sorting.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
138
diff
changeset
|
184 |
Sorting order for completion category. |
7e8f523b66af
Add completion sorting.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
138
diff
changeset
|
185 |
**Values:** sort, direct, reverse, append, prepend |
129 | 186 |
|
187 |
<a name="command.arguments.table"></a> |
|
188 |
### command arguments table |
|
189 |
It can parse barewords (with escapes), double-quoted strings (with escapes), single-quoted strings (without escapes), options and arguments. |
|
190 |
Arguments are separated only by whitespace, so, consequential quoted strings or barewords are one argument. |
|
191 |
This strings are equal: |
|
192 |
||
193 |
* ab\ cd\'e\\f\" |
|
194 |
* "ab cd'e\\f\"" |
|
195 |
* 'ab cd'\''e\f"' |
|
196 |
* ab" cd'"'e\f"' |
|
197 |
||
198 |
Returned table have option names as keys, option values as values, and arguments as sequential members. -- option is supported. |
|
199 |
Example: "-t jid -m 9 -- -aa bb cc" will result in { t = 'jid', m = 9, '-aa', 'bb', 'cc' } |
|
200 |
Implementation notes: |
|
201 |
||
202 |
* All options should be before any arguments. First non-option argument disables options recognizing. |
|
203 |
* 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. |
|
204 |
* Escape character just before EOL is preserved. |
|
205 |
||
206 |
<a name="command.function"></a> |
|
207 |
### command function |
|
208 |
Function to handle newly registered command. |
|
209 |
Argument type passed depends on how command is registered. |
|
210 |
**Arguments:** string (arguments) or [command arguments table](#command.arguments.table) |
|
211 |
||
212 |
<a name="main.parse.args"></a> |
|
213 |
### main.parse_args |
|
214 |
Function to parse command argument string to [command arguments table](#command.arguments.table). |
|
215 |
**Arguments:** string |
|
216 |
**Return values:** table |
|
217 |
||
218 |
<a name="main.add.category"></a> |
|
219 |
### main.add_category |
|
220 |
Adds completion category. |
|
142
7e8f523b66af
Add completion sorting.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
138
diff
changeset
|
221 |
**Arguments:** table (values are used as words for completion, optional), argument enum value ([completion sorting order](#completion.sorting.order), optional) |
129 | 222 |
**Return values:** integer (category id, in fact [completion type](#completion.type)) or nil |
223 |
||
224 |
<a name="main.del.category"></a> |
|
225 |
### main.del_category |
|
226 |
Removes completion category. |
|
227 |
**Arguments:** integer (category id) |
|
228 |
||
229 |
<a name="main.add.completion"></a> |
|
230 |
### main.add_completion |
|
231 |
Adds word to a completion list. |
|
232 |
**Arguments:** integer (completion group id), string (word) |
|
233 |
||
234 |
<a name="main.del.completion"></a> |
|
235 |
### main.del_completion |
|
236 |
Removes word from a completion list. |
|
237 |
**Arguments:** integer (completion group id), string (word) |
|
238 |
||
239 |
<a name="main.command"></a> |
|
240 |
### main.command |
|
241 |
Associates mcabber command name and lua function. |
|
242 |
As a completion you can also specify a string name (see [completion type](#completion.type)) instead of table, for non-builtin, you can just pass integer id. |
|
243 |
Note, that for now there are no way to unregister completion group, so, resources can be exausted easily. |
|
244 |
Also note, that it ignores keys in a completion table. |
|
245 |
**Arguments:** string (command name), [command function](#command.function), boolean (parse args flag, optional), table (completions, optional)/[completion type](#completion.type) (or integer comletion group id, optional) |
|
246 |
**Return values:** userdata (command object) |
|
247 |
||
248 |
<a name="command:del"></a> |
|
249 |
### command:del |
|
250 |
Unregisters given command from mcabber. Object will be destroyed later. |
|
251 |
||
252 |
<a name="timer.function"></a> |
|
253 |
### timer function |
|
254 |
Function, that will be called periodically until it returns false. |
|
255 |
**Return values:** boolean |
|
256 |
||
257 |
<a name="main.timer"></a> |
|
258 |
### main.timer |
|
259 |
Creates new [timer function](#timer.function), that will be called periodically. |
|
260 |
**Arguments:** integer (interval, seconds), [timer function](#timer.function) |
|
261 |
||
262 |
<a name="background.reading.function"></a> |
|
263 |
### background reading function |
|
264 |
Function, that processes output from pipe in asynchronous way. |
|
265 |
**Arguments:** string (data) or nil (eof) |
|
266 |
**Return values:** boolean (false if reading should be terminated) |
|
267 |
||
268 |
<a name="main.bgread"></a> |
|
269 |
### main.bgread |
|
270 |
Runs specified command and passes its output to a given function. |
|
271 |
**Arguments:** string (command), [background reading function](#background.reading.function) |
|
272 |
||
273 |
<a name="hook.handler.result"></a> |
|
274 |
### hook handler result |
|
275 |
What to do with hook processing afterwards |
|
276 |
**Values:** proceed, stop, drop |
|
277 |
||
278 |
<a name="hook.handler.priority"></a> |
|
279 |
### hook handler priority |
|
280 |
Feel free to specify just a number instead of some preset value. |
|
281 |
**Values:** high, default, idle-high, idle, low |
|
282 |
||
283 |
<a name="hook.function"></a> |
|
284 |
### hook function |
|
285 |
Function to be called, when hook will be processsed. |
|
286 |
XXX: we can provide object as argument, but is this necessary? |
|
287 |
**Arguments:** table (arguments hash) |
|
288 |
**Return values:** [hook handler result](#hook.handler.result) |
|
289 |
||
138 | 290 |
<a name="main.hook.run"></a> |
291 |
### main.hook_run |
|
292 |
Runs handlers for given hook with supplied arguments. |
|
293 |
**Arguments:** string (hook name), table (hook arguments) |
|
294 |
**Return values:** [return enum field](#return.enum.field) ([hook handler result](#hook.handler.result)) |
|
295 |
||
129 | 296 |
<a name="main.hook"></a> |
297 |
### main.hook |
|
298 |
Installs hook handler, returns an object, that you need to keep until |
|
299 |
hook handling is no more needed. |
|
300 |
**Arguments:** string (hook name), [hook function](#hook.function), integer (priority, optional) |
|
301 |
**Return values:** userdata (hook object) |
|
302 |
||
303 |
<a name="hook:del"></a> |
|
304 |
### hook:del |
|
305 |
Unregisters given hook handler from mcabber. Object will be destroyed later. |
|
306 |
||
307 |
<a name="guard.function"></a> |
|
308 |
### guard function |
|
309 |
Function to be called, when option changes it's value. |
|
310 |
Old option value is still accessible through [main.option](#main.option). |
|
311 |
**Arguments:** string (key), string (new value) |
|
312 |
**Return values:** string (value to save in hash table) |
|
313 |
||
314 |
<a name="main.add.guard"></a> |
|
315 |
### main.add_guard |
|
316 |
Installs option guard for given option. |
|
317 |
**Arguments:** string ( option name ), [guard function](#guard.function) |
|
318 |
**Return values:** boolean ( success ) |
|
319 |
||
320 |
<a name="main.del.guard"></a> |
|
321 |
### main.del_guard |
|
322 |
Removes option guard from given option. |
|
323 |
By default, lua will refuse to remove guards, not installed |
|
324 |
by lua. Still, you can force guard removal. |
|
325 |
**Arguments:** string ( option name ), boolean ( force removal ) |
|
326 |
**Return values:** boolean ( success ) |
|
327 |
||
328 |
- - - |
|
329 |
||
330 |
- - - |
|
331 |
||
130 | 332 |
<a name="Utility.Lua.Routines"></a> |
333 |
## Utility Lua Routines |
|
334 |
To handle conversion of enums and flag fields to/from human-readable strings. |
|
335 |
||
129 | 336 |
<a name="argument.enum.field"></a> |
130 | 337 |
### argument enum field |
129 | 338 |
String that will be converted to number or just plain number, that will be passed as is. |
339 |
Note, that if enum name is not recognized no error will be raised and default vale will be used. |
|
340 |
||
341 |
<a name="return.enum.field"></a> |
|
342 |
### return enum field |
|
343 |
String. If no string found, plain number will be returned. |
|
344 |
||
345 |
<a name="argument.flags.field"></a> |
|
346 |
### argument flags field |
|
347 |
Can be just plain number, then it is passed as is. |
|
348 |
Can be a string, then it is recognized as a single enabled flag. |
|
349 |
Or can be a table of the following format: |
|
350 |
||
351 |
* integer keys should have string values, that will be used as enabled flag names or numerical values, that will be just ORed; |
|
352 |
* string keys should be flag names, that will be enabled, if corresponding value contains true value. |
|
353 |
||
354 |
<a name="returned.flags.field"></a> |
|
355 |
### returned flags field |
|
356 |
Is always a table with present flag names as keys with true values. |
|
357 |
Not present flags are not present in table either. |
|
358 |
Not recognized values, if present, will be stored as a number in a first sequential table member (table[1]). |
|
359 |
||
360 |
- - - |