mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 21:36:37 +02:00
core: add pointer in some callbacks (closes #406)
This pointer is the first argument received by callbacks, and the existing argument "data" is now automatically freed by WeeChat when the object containing the callback is removed. With this new pointer, the linked list of callbacks in scripts has been removed. This will improve speed of scripts (using a lot of hooks), reduce memory used by scripts and reduce time to unload scripts. Following functions are affected in the C API: * exec_on_files * config_new * config_new_section * config_new_option * hook_command * hook_command_run * hook_timer * hook_fd * hook_process * hook_process_hashtable * hook_connect * hook_print * hook_signal * hook_hsignal * hook_config * hook_completion * hook_modifier * hook_info * hook_info_hashtable * hook_infolist * hook_hdata * hook_focus * unhook_all_plugin * buffer_new * bar_item_new * upgrade_new * upgrade_read
This commit is contained in:
+378
-315
File diff suppressed because it is too large
Load Diff
@@ -24,10 +24,12 @@
|
||||
extern struct luaL_Reg weechat_lua_api_funcs[];
|
||||
extern struct t_lua_const weechat_lua_api_consts[];
|
||||
|
||||
extern int weechat_lua_api_buffer_input_data_cb (void *data,
|
||||
extern int weechat_lua_api_buffer_input_data_cb (const void *pointer,
|
||||
void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
const char *input_data);
|
||||
extern int weechat_lua_api_buffer_close_cb (void *data,
|
||||
extern int weechat_lua_api_buffer_close_cb (const void *pointer,
|
||||
void *data,
|
||||
struct t_gui_buffer *buffer);
|
||||
|
||||
#endif /* WEECHAT_LUA_API_H */
|
||||
|
||||
@@ -606,12 +606,14 @@ weechat_lua_unload_all ()
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
weechat_lua_command_cb (const void *pointer, void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
char *ptr_name, *path_script;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
|
||||
@@ -707,11 +709,13 @@ weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_completion_cb (void *data, const char *completion_item,
|
||||
weechat_lua_completion_cb (const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
@@ -726,9 +730,11 @@ weechat_lua_completion_cb (void *data, const char *completion_item,
|
||||
*/
|
||||
|
||||
struct t_hdata *
|
||||
weechat_lua_hdata_cb (void *data, const char *hdata_name)
|
||||
weechat_lua_hdata_cb (const void *pointer, void *data,
|
||||
const char *hdata_name)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
|
||||
return plugin_script_hdata_script (weechat_plugin,
|
||||
@@ -741,10 +747,12 @@ weechat_lua_hdata_cb (void *data, const char *hdata_name)
|
||||
*/
|
||||
|
||||
struct t_infolist *
|
||||
weechat_lua_infolist_cb (void *data, const char *infolist_name,
|
||||
void *pointer, const char *arguments)
|
||||
weechat_lua_infolist_cb (const void *pointer, void *data,
|
||||
const char *infolist_name,
|
||||
void *obj_pointer, const char *arguments)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
|
||||
if (!infolist_name || !infolist_name[0])
|
||||
@@ -753,7 +761,7 @@ weechat_lua_infolist_cb (void *data, const char *infolist_name,
|
||||
if (weechat_strcasecmp (infolist_name, "lua_script") == 0)
|
||||
{
|
||||
return plugin_script_infolist_list_scripts (weechat_lua_plugin,
|
||||
lua_scripts, pointer,
|
||||
lua_scripts, obj_pointer,
|
||||
arguments);
|
||||
}
|
||||
|
||||
@@ -765,10 +773,12 @@ weechat_lua_infolist_cb (void *data, const char *infolist_name,
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_signal_debug_dump_cb (void *data, const char *signal,
|
||||
weechat_lua_signal_debug_dump_cb (const void *pointer, void *data,
|
||||
const char *signal,
|
||||
const char *type_data, void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
@@ -787,10 +797,12 @@ weechat_lua_signal_debug_dump_cb (void *data, const char *signal,
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_signal_debug_libs_cb (void *data, const char *signal,
|
||||
weechat_lua_signal_debug_libs_cb (const void *pointer, void *data,
|
||||
const char *signal,
|
||||
const char *type_data, void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
@@ -805,38 +817,21 @@ weechat_lua_signal_debug_libs_cb (void *data, const char *signal,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback called when a buffer is closed.
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_signal_buffer_closed_cb (void *data, const char *signal,
|
||||
const char *type_data, void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
|
||||
if (signal_data)
|
||||
plugin_script_remove_buffer_callbacks (lua_scripts, signal_data);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Timer for executing actions.
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_timer_action_cb (void *data, int remaining_calls)
|
||||
weechat_lua_timer_action_cb (const void *pointer, void *data,
|
||||
int remaining_calls)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) remaining_calls;
|
||||
|
||||
if (data)
|
||||
if (pointer)
|
||||
{
|
||||
if (data == &lua_action_install_list)
|
||||
if (pointer == &lua_action_install_list)
|
||||
{
|
||||
plugin_script_action_install (weechat_lua_plugin,
|
||||
lua_scripts,
|
||||
@@ -845,7 +840,7 @@ weechat_lua_timer_action_cb (void *data, int remaining_calls)
|
||||
&lua_quiet,
|
||||
&lua_action_install_list);
|
||||
}
|
||||
else if (data == &lua_action_remove_list)
|
||||
else if (pointer == &lua_action_remove_list)
|
||||
{
|
||||
plugin_script_action_remove (weechat_lua_plugin,
|
||||
lua_scripts,
|
||||
@@ -853,7 +848,7 @@ weechat_lua_timer_action_cb (void *data, int remaining_calls)
|
||||
&lua_quiet,
|
||||
&lua_action_remove_list);
|
||||
}
|
||||
else if (data == &lua_action_autoload_list)
|
||||
else if (pointer == &lua_action_autoload_list)
|
||||
{
|
||||
plugin_script_action_autoload (weechat_lua_plugin,
|
||||
&lua_quiet,
|
||||
@@ -869,11 +864,13 @@ weechat_lua_timer_action_cb (void *data, int remaining_calls)
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_signal_script_action_cb (void *data, const char *signal,
|
||||
weechat_lua_signal_script_action_cb (const void *pointer, void *data,
|
||||
const char *signal,
|
||||
const char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
|
||||
if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
|
||||
@@ -884,7 +881,7 @@ weechat_lua_signal_script_action_cb (void *data, const char *signal,
|
||||
(const char *)signal_data);
|
||||
weechat_hook_timer (1, 0, 1,
|
||||
&weechat_lua_timer_action_cb,
|
||||
&lua_action_install_list);
|
||||
&lua_action_install_list, NULL);
|
||||
}
|
||||
else if (strcmp (signal, "lua_script_remove") == 0)
|
||||
{
|
||||
@@ -892,7 +889,7 @@ weechat_lua_signal_script_action_cb (void *data, const char *signal,
|
||||
(const char *)signal_data);
|
||||
weechat_hook_timer (1, 0, 1,
|
||||
&weechat_lua_timer_action_cb,
|
||||
&lua_action_remove_list);
|
||||
&lua_action_remove_list, NULL);
|
||||
}
|
||||
else if (strcmp (signal, "lua_script_autoload") == 0)
|
||||
{
|
||||
@@ -900,7 +897,7 @@ weechat_lua_signal_script_action_cb (void *data, const char *signal,
|
||||
(const char *)signal_data);
|
||||
weechat_hook_timer (1, 0, 1,
|
||||
&weechat_lua_timer_action_cb,
|
||||
&lua_action_autoload_list);
|
||||
&lua_action_autoload_list, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -924,7 +921,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
init.callback_infolist = &weechat_lua_infolist_cb;
|
||||
init.callback_signal_debug_dump = &weechat_lua_signal_debug_dump_cb;
|
||||
init.callback_signal_debug_libs = &weechat_lua_signal_debug_libs_cb;
|
||||
init.callback_signal_buffer_closed = &weechat_lua_signal_buffer_closed_cb;
|
||||
init.callback_signal_script_action = &weechat_lua_signal_script_action_cb;
|
||||
init.callback_load_file = &weechat_lua_load_cb;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user