2
* weechat-lua-api.c - lua API functions
2
4
* Copyright (C) 2006-2007 Emmanuel Bouthenot <kolter@openics.org>
3
* Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org>
5
* Copyright (C) 2006-2013 Sebastien Helleu <flashcode@flashtux.org>
6
* Copyright (C) 2012 Simon Arlott
5
8
* This file is part of WeeChat, the extensible chat client.
292
272
API_RETURN_STRING(result);
296
* weechat_lua_api_string_match: return 1 if string matches a mask
297
* mask can begin or end with "*", no other "*"
298
* are allowed inside mask
302
276
weechat_lua_api_string_match (lua_State *L)
369
327
API_RETURN_INT(value);
373
* weechat_lua_api_string_mask_to_regex: convert a mask (string with only
374
* "*" as wildcard) to a regex, paying
375
* attention to special chars in a
380
331
weechat_lua_api_string_mask_to_regex (lua_State *L)
459
395
API_RETURN_STRING(result);
463
* weechat_lua_api_mkdir_home: create a directory in WeeChat home
399
weechat_lua_api_string_eval_expression (lua_State *L)
402
struct t_hashtable *pointers, *extra_vars;
405
API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
406
if (lua_gettop (lua_current_interpreter) < 3)
407
API_WRONG_ARGS(API_RETURN_EMPTY);
409
expr = lua_tostring (lua_current_interpreter, -3);
410
pointers = weechat_lua_tohashtable (lua_current_interpreter, -2,
411
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
412
WEECHAT_HASHTABLE_STRING,
413
WEECHAT_HASHTABLE_POINTER);
414
extra_vars = weechat_lua_tohashtable (lua_current_interpreter, -1,
415
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
416
WEECHAT_HASHTABLE_STRING,
417
WEECHAT_HASHTABLE_STRING);
419
result = weechat_string_eval_expression (expr, pointers, extra_vars);
422
weechat_hashtable_free (pointers);
424
weechat_hashtable_free (extra_vars);
426
API_RETURN_STRING_FREE(result);
467
430
weechat_lua_api_mkdir_home (lua_State *L)
923
808
API_RETURN_STRING_FREE(result);
927
* weechat_lua_api_config_read_cb: callback for reading option in section
931
812
weechat_lua_api_config_read_cb (void *data,
932
813
struct t_config_file *config_file,
971
852
return WEECHAT_CONFIG_OPTION_SET_ERROR;
975
* weechat_lua_api_config_section_write_cb: callback for writing section
979
856
weechat_lua_api_config_section_write_cb (void *data,
980
857
struct t_config_file *config_file,
1014
891
return WEECHAT_CONFIG_WRITE_ERROR;
1018
* weechat_lua_api_config_section_write_default_cb: callback for writing
1019
* default values for section
1023
895
weechat_lua_api_config_section_write_default_cb (void *data,
1024
896
struct t_config_file *config_file,
1058
930
return WEECHAT_CONFIG_WRITE_ERROR;
1062
* weechat_lua_api_config_section_create_option_cb: callback to create an option
1066
934
weechat_lua_api_config_section_create_option_cb (void *data,
1067
935
struct t_config_file *config_file,
1107
975
return WEECHAT_CONFIG_OPTION_SET_ERROR;
1111
* weechat_lua_api_config_section_delete_option_cb: callback to delete an option
1115
979
weechat_lua_api_config_section_delete_option_cb (void *data,
1116
980
struct t_config_file *config_file,
1238
1094
API_RETURN_STRING_FREE(result);
1242
* weechat_lua_api_config_option_check_value_cb: callback for checking new
1247
1098
weechat_lua_api_config_option_check_value_cb (void *data,
1248
1099
struct t_config_option *option,
2133
1837
context = lua_tostring (lua_current_interpreter, -2);
2134
1838
hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1,
2135
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
1839
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
1840
WEECHAT_HASHTABLE_STRING,
1841
WEECHAT_HASHTABLE_STRING);
2137
1843
num_keys = weechat_key_bind (context, hashtable);
2311
* weechat_lua_api_hook_command_cb: callback for command hooked
2315
1988
weechat_lua_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
2316
1989
int argc, char **argv, char **argv_eol)
2608
2253
API_RETURN_STRING_FREE(result);
2612
* weechat_lua_api_hook_process_cb: callback for process hooked
2616
2257
weechat_lua_api_hook_process_cb (void *data,
2617
2258
const char *command, int return_code,
2702
2334
command = lua_tostring (lua_current_interpreter, -5);
2703
2335
options = weechat_lua_tohashtable (lua_current_interpreter, -4,
2704
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
2336
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
2337
WEECHAT_HASHTABLE_STRING,
2338
WEECHAT_HASHTABLE_STRING);
2705
2339
timeout = lua_tonumber (lua_current_interpreter, -3);
2706
2340
function = lua_tostring (lua_current_interpreter, -2);
2707
2341
data = lua_tostring (lua_current_interpreter, -1);
2721
2355
API_RETURN_STRING_FREE(result);
2725
* weechat_lua_api_hook_connect_cb: callback for connect hooked
2729
2359
weechat_lua_api_hook_connect_cb (void *data, int status, int gnutls_rc,
2730
const char *error, const char *ip_address)
2360
int sock, const char *error,
2361
const char *ip_address)
2732
2363
struct t_plugin_script_cb *script_callback;
2734
char str_status[32], str_gnutls_rc[32];
2365
char str_status[32], str_gnutls_rc[32], str_sock[32];
2735
2366
char empty_arg[1] = { '\0' };
2742
2373
snprintf (str_status, sizeof (str_status), "%d", status);
2743
2374
snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc);
2375
snprintf (str_sock, sizeof (str_sock), "%d", sock);
2745
2377
func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
2746
2378
func_argv[1] = str_status;
2747
2379
func_argv[2] = str_gnutls_rc;
2748
func_argv[3] = (ip_address) ? (char *)ip_address : empty_arg;
2749
func_argv[4] = (error) ? (char *)error : empty_arg;
2380
func_argv[3] = str_sock;
2381
func_argv[4] = (ip_address) ? (char *)ip_address : empty_arg;
2382
func_argv[5] = (error) ? (char *)error : empty_arg;
2751
2384
rc = (int *) weechat_lua_exec (script_callback->script,
2752
2385
WEECHAT_SCRIPT_EXEC_INT,
2753
2386
script_callback->function,
2754
"sssss", func_argv);
2387
"ssssss", func_argv);
2757
2390
ret = WEECHAT_RC_ERROR;
2767
2400
return WEECHAT_RC_ERROR;
2771
* weechat_lua_api_hook_connect: hook a connection
2775
2404
weechat_lua_api_hook_connect (lua_State *L)
2777
2406
const char *proxy, *address, *local_hostname, *function, *data;
2778
int port, sock, ipv6;
2407
int port, ipv6, retry;
2781
2410
API_FUNC(1, "hook_connect", API_RETURN_EMPTY);
2785
2414
proxy = lua_tostring (lua_current_interpreter, -8);
2786
2415
address = lua_tostring (lua_current_interpreter, -7);
2787
2416
port = lua_tonumber (lua_current_interpreter, -6);
2788
sock = lua_tonumber (lua_current_interpreter, -5);
2789
ipv6 = lua_tonumber (lua_current_interpreter, -4);
2417
ipv6 = lua_tonumber (lua_current_interpreter, -5);
2418
retry = lua_tonumber (lua_current_interpreter, -4);
2790
2419
local_hostname = lua_tostring (lua_current_interpreter, -3);
2791
2420
function = lua_tostring (lua_current_interpreter, -2);
2792
2421
data = lua_tostring (lua_current_interpreter, -1);
2909
2530
API_RETURN_STRING_FREE(result);
2913
* weechat_lua_api_hook_signal_cb: callback for signal hooked
2917
2534
weechat_lua_api_hook_signal_cb (void *data, const char *signal,
2918
2535
const char *type_data, void *signal_data)
3124
2721
signal = lua_tostring (lua_current_interpreter, -2);
3125
2722
hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1,
3126
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
2723
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
2724
WEECHAT_HASHTABLE_STRING,
2725
WEECHAT_HASHTABLE_STRING);
3128
2727
weechat_hook_hsignal_send (signal, hashtable);
3201
2792
API_RETURN_STRING_FREE(result);
3205
* weechat_lua_api_hook_completion_cb: callback for completion hooked
3209
2796
weechat_lua_api_hook_completion_cb (void *data, const char *completion_item,
3210
2797
struct t_gui_buffer *buffer,
3308
* weechat_lua_api_hook_modifier_cb: callback for modifier hooked
3312
2887
weechat_lua_api_hook_modifier_cb (void *data, const char *modifier,
3313
2888
const char *modifier_data,
3447
3006
API_RETURN_STRING_FREE(result);
3451
* weechat_lua_api_hook_info_hashtable_cb: callback for info_hashtable hooked
3454
3009
struct t_hashtable *
3455
3010
weechat_lua_api_hook_info_hashtable_cb (void *data, const char *info_name,
3456
3011
struct t_hashtable *hashtable)
3511
3062
API_RETURN_STRING_FREE(result);
3515
* weechat_lua_api_hook_infolist_cb: callback for infolist hooked
3518
3065
struct t_infolist *
3519
3066
weechat_lua_api_hook_infolist_cb (void *data, const char *info_name,
3520
3067
void *pointer, const char *arguments)
3582
3125
API_RETURN_STRING_FREE(result);
3586
* weechat_lua_api_hook_focus_cb: callback for focus hooked
3589
3128
struct t_hashtable *
3590
3129
weechat_lua_api_hook_focus_cb (void *data,
3591
3130
struct t_hashtable *info)
4592
3964
API_RETURN_STRING_FREE(result);
4596
* weechat_lua_api_bar_item_build_cb: callback for building bar item
4600
3968
weechat_lua_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item,
4601
3969
struct t_gui_window *window)
4896
4220
info_name = lua_tostring (lua_current_interpreter, -2);
4897
4221
table = weechat_lua_tohashtable (lua_current_interpreter, -1,
4898
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
4222
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
4223
WEECHAT_HASHTABLE_STRING,
4224
WEECHAT_HASHTABLE_STRING);
4900
4226
result_hashtable = weechat_info_get_hashtable (info_name, table);
5691
4871
hdata = lua_tostring (lua_current_interpreter, -3);
5692
4872
pointer = lua_tostring (lua_current_interpreter, -2);
5693
4873
hashtable = weechat_lua_tohashtable (lua_current_interpreter, -1,
5694
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
4874
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
4875
WEECHAT_HASHTABLE_STRING,
4876
WEECHAT_HASHTABLE_STRING);
5696
4878
value = weechat_hdata_update (API_STR2PTR(hdata),
5697
4879
API_STR2PTR(pointer),
5395
weechat_lua_api_constant_weechat_hook_connect_socket_error (lua_State *L)
5397
/* make C compiler happy */
5400
lua_pushnumber (lua_current_interpreter, WEECHAT_HOOK_CONNECT_SOCKET_ERROR);
6237
5405
weechat_lua_api_constant_weechat_hook_signal_string (lua_State *L)
6239
5407
/* make C compiler happy */
6282
5450
API_DEF_FUNC(string_remove_color),
6283
5451
API_DEF_FUNC(string_is_command_char),
6284
5452
API_DEF_FUNC(string_input_for_buffer),
5453
API_DEF_FUNC(string_eval_expression),
6285
5454
API_DEF_FUNC(mkdir_home),
6286
5455
API_DEF_FUNC(mkdir),
6287
5456
API_DEF_FUNC(mkdir_parents),
6496
5665
{ "WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR", &weechat_lua_api_constant_weechat_hook_connect_gnutls_handshake_error },
6497
5666
{ "WEECHAT_HOOK_CONNECT_MEMORY_ERROR", &weechat_lua_api_constant_weechat_hook_connect_memory_error },
6498
5667
{ "WEECHAT_HOOK_CONNECT_TIMEOUT", &weechat_lua_api_constant_weechat_hook_connect_timeout },
5668
{ "WEECHAT_HOOK_CONNECT_SOCKET_ERROR", &weechat_lua_api_constant_weechat_hook_connect_socket_error },
6500
5670
{ "WEECHAT_HOOK_SIGNAL_STRING", &weechat_lua_api_constant_weechat_hook_signal_string },
6501
5671
{ "WEECHAT_HOOK_SIGNAL_INT", &weechat_lua_api_constant_weechat_hook_signal_int },