summaryrefslogtreecommitdiff
path: root/src/plugins/lua
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2016-03-21 18:11:21 +0100
committerSébastien Helleu <flashcode@flashtux.org>2016-03-21 18:11:21 +0100
commitcf6aca1619c32422a43fa3d82e0674f6b7b49fe9 (patch)
tree65392ef12eab877f544fe306fe0abb98214ddebd /src/plugins/lua
parent6d764b64c50adb19309a9de14bfeafac648ab47a (diff)
downloadweechat-cf6aca1619c32422a43fa3d82e0674f6b7b49fe9.zip
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
Diffstat (limited to 'src/plugins/lua')
-rw-r--r--src/plugins/lua/weechat-lua-api.c681
-rw-r--r--src/plugins/lua/weechat-lua-api.h6
-rw-r--r--src/plugins/lua/weechat-lua.c70
3 files changed, 409 insertions, 348 deletions
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index ac9ad7397..1900aed0b 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -33,7 +33,6 @@
#include "../weechat-plugin.h"
#include "../plugin-script.h"
#include "../plugin-script-api.h"
-#include "../plugin-script-callback.h"
#include "weechat-lua.h"
@@ -782,24 +781,26 @@ API_FUNC(list_free)
}
int
-weechat_lua_api_config_reload_cb (void *data,
+weechat_lua_api_config_reload_cb (const void *pointer, void *data,
struct t_config_file *config_file)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(config_file);
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ss", func_argv);
if (!rc)
@@ -842,29 +843,31 @@ API_FUNC(config_new)
}
int
-weechat_lua_api_config_read_cb (void *data,
+weechat_lua_api_config_read_cb (const void *pointer, void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name, const char *value)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[5];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(config_file);
func_argv[2] = API_PTR2STR(section);
func_argv[3] = (option_name) ? (char *)option_name : empty_arg;
func_argv[4] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sssss", func_argv);
if (!rc)
@@ -886,26 +889,28 @@ weechat_lua_api_config_read_cb (void *data,
}
int
-weechat_lua_api_config_section_write_cb (void *data,
+weechat_lua_api_config_section_write_cb (const void *pointer, void *data,
struct t_config_file *config_file,
const char *section_name)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(config_file);
func_argv[2] = (section_name) ? (char *)section_name : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -925,26 +930,28 @@ weechat_lua_api_config_section_write_cb (void *data,
}
int
-weechat_lua_api_config_section_write_default_cb (void *data,
+weechat_lua_api_config_section_write_default_cb (const void *pointer, void *data,
struct t_config_file *config_file,
const char *section_name)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(config_file);
func_argv[2] = (section_name) ? (char *)section_name : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -964,30 +971,32 @@ weechat_lua_api_config_section_write_default_cb (void *data,
}
int
-weechat_lua_api_config_section_create_option_cb (void *data,
+weechat_lua_api_config_section_create_option_cb (const void *pointer, void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[5];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(config_file);
func_argv[2] = API_PTR2STR(section);
func_argv[3] = (option_name) ? (char *)option_name : empty_arg;
func_argv[4] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sssss", func_argv);
if (!rc)
@@ -1009,28 +1018,30 @@ weechat_lua_api_config_section_create_option_cb (void *data,
}
int
-weechat_lua_api_config_section_delete_option_cb (void *data,
+weechat_lua_api_config_section_delete_option_cb (const void *pointer, void *data,
struct t_config_file *config_file,
struct t_config_section *section,
struct t_config_option *option)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[4];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(config_file);
func_argv[2] = API_PTR2STR(section);
func_argv[3] = API_PTR2STR(option);
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ssss", func_argv);
if (!rc)
@@ -1082,27 +1093,29 @@ API_FUNC(config_new_section)
function_delete_option = lua_tostring (L, -2);
data_delete_option = lua_tostring (L, -1);
- result = API_PTR2STR(plugin_script_api_config_new_section (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(config_file),
- name,
- user_can_add_options,
- user_can_delete_options,
- &weechat_lua_api_config_read_cb,
- function_read,
- data_read,
- &weechat_lua_api_config_section_write_cb,
- function_write,
- data_write,
- &weechat_lua_api_config_section_write_default_cb,
- function_write_default,
- data_write_default,
- &weechat_lua_api_config_section_create_option_cb,
- function_create_option,
- data_create_option,
- &weechat_lua_api_config_section_delete_option_cb,
- function_delete_option,
- data_delete_option));
+ result = API_PTR2STR(
+ plugin_script_api_config_new_section (
+ weechat_lua_plugin,
+ lua_current_script,
+ API_STR2PTR(config_file),
+ name,
+ user_can_add_options,
+ user_can_delete_options,
+ &weechat_lua_api_config_read_cb,
+ function_read,
+ data_read,
+ &weechat_lua_api_config_section_write_cb,
+ function_write,
+ data_write,
+ &weechat_lua_api_config_section_write_default_cb,
+ function_write_default,
+ data_write_default,
+ &weechat_lua_api_config_section_create_option_cb,
+ function_create_option,
+ data_create_option,
+ &weechat_lua_api_config_section_delete_option_cb,
+ function_delete_option,
+ data_delete_option));
API_RETURN_STRING_FREE(result);
}
@@ -1126,26 +1139,28 @@ API_FUNC(config_search_section)
}
int
-weechat_lua_api_config_option_check_value_cb (void *data,
+weechat_lua_api_config_option_check_value_cb (const void *pointer, void *data,
struct t_config_option *option,
const char *value)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(option);
func_argv[2] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -1165,24 +1180,26 @@ weechat_lua_api_config_option_check_value_cb (void *data,
}
void
-weechat_lua_api_config_option_change_cb (void *data,
+weechat_lua_api_config_option_change_cb (const void *pointer, void *data,
struct t_config_option *option)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(option);
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ss", func_argv);
if (func_argv[1])
@@ -1194,24 +1211,26 @@ weechat_lua_api_config_option_change_cb (void *data,
}
void
-weechat_lua_api_config_option_delete_cb (void *data,
+weechat_lua_api_config_option_delete_cb (const void *pointer, void *data,
struct t_config_option *option)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(option);
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ss", func_argv);
if (func_argv[1])
@@ -1655,9 +1674,7 @@ API_FUNC(config_option_free)
option = lua_tostring (L, -1);
- plugin_script_api_config_option_free (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(option));
+ weechat_config_option_free (API_STR2PTR(option));
API_RETURN_OK;
}
@@ -1672,9 +1689,7 @@ API_FUNC(config_section_free_options)
section = lua_tostring (L, -1);
- plugin_script_api_config_section_free_options (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(section));
+ weechat_config_section_free_options (API_STR2PTR(section));
API_RETURN_OK;
}
@@ -1689,9 +1704,7 @@ API_FUNC(config_section_free)
section = lua_tostring (L, -1);
- plugin_script_api_config_section_free (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(section));
+ weechat_config_section_free (API_STR2PTR(section));
API_RETURN_OK;
}
@@ -1706,9 +1719,7 @@ API_FUNC(config_free)
config_file = lua_tostring (L, -1);
- plugin_script_api_config_free (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(config_file));
+ weechat_config_free (API_STR2PTR(config_file));
API_RETURN_OK;
}
@@ -1975,28 +1986,31 @@ API_FUNC(log_print)
}
int
-weechat_lua_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
+weechat_lua_api_hook_command_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
/* make C compiler happy */
(void) argv;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(buffer);
func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -2048,25 +2062,28 @@ API_FUNC(hook_command)
}
int
-weechat_lua_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
+weechat_lua_api_hook_command_run_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer,
const char *command)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(buffer);
func_argv[2] = (command) ? (char *)command : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -2109,26 +2126,29 @@ API_FUNC(hook_command_run)
}
int
-weechat_lua_api_hook_timer_cb (void *data, int remaining_calls)
+weechat_lua_api_hook_timer_cb (const void *pointer, void *data,
+ int remaining_calls)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[2];
char str_remaining_calls[32], empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
snprintf (str_remaining_calls, sizeof (str_remaining_calls),
"%d", remaining_calls);
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = str_remaining_calls;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ss", func_argv);
if (!rc)
@@ -2174,25 +2194,27 @@ API_FUNC(hook_timer)
}
int
-weechat_lua_api_hook_fd_cb (void *data, int fd)
+weechat_lua_api_hook_fd_cb (const void *pointer, void *data, int fd)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[2];
char str_fd[32], empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
snprintf (str_fd, sizeof (str_fd), "%d", fd);
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = str_fd;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ss", func_argv);
if (!rc)
@@ -2240,28 +2262,30 @@ API_FUNC(hook_fd)
}
int
-weechat_lua_api_hook_process_cb (void *data,
+weechat_lua_api_hook_process_cb (const void *pointer, void *data,
const char *command, int return_code,
const char *out, const char *err)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[5];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (command) ? (char *)command : empty_arg;
func_argv[2] = &return_code;
func_argv[3] = (out) ? (char *)out : empty_arg;
func_argv[4] = (err) ? (char *)err : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ssiss", func_argv);
if (!rc)
@@ -2340,34 +2364,37 @@ API_FUNC(hook_process_hashtable)
}
int
-weechat_lua_api_hook_connect_cb (void *data, int status, int gnutls_rc,
+weechat_lua_api_hook_connect_cb (const void *pointer, void *data,
+ int status, int gnutls_rc,
int sock, const char *error,
const char *ip_address)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[6];
char str_status[32], str_gnutls_rc[32], str_sock[32];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
snprintf (str_status, sizeof (str_status), "%d", status);
snprintf (str_gnutls_rc, sizeof (str_gnutls_rc), "%d", gnutls_rc);
snprintf (str_sock, sizeof (str_sock), "%d", sock);
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = str_status;
func_argv[2] = str_gnutls_rc;
func_argv[3] = str_sock;
func_argv[4] = (ip_address) ? (char *)ip_address : empty_arg;
func_argv[5] = (error) ? (char *)error : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ssssss", func_argv);
if (!rc)
@@ -2423,28 +2450,31 @@ API_FUNC(hook_connect)
}
int
-weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
+weechat_lua_api_hook_print_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer,
time_t date,
int tags_count, const char **tags,
int displayed, int highlight,
const char *prefix, const char *message)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[8];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
static char timebuffer[64];
int *rc, ret;
/* make C compiler happy */
(void) tags_count;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
snprintf (timebuffer, sizeof (timebuffer), "%ld", (long int)date);
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(buffer);
func_argv[2] = timebuffer;
func_argv[3] = weechat_string_build_with_split_string (tags, ",");
@@ -2455,9 +2485,9 @@ weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
func_argv[6] = (prefix) ? (char *)prefix : empty_arg;
func_argv[7] = (message) ? (char *)message : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ssssiiss", func_argv);
if (!rc)
@@ -2509,20 +2539,23 @@ API_FUNC(hook_print)
}
int
-weechat_lua_api_hook_signal_cb (void *data, const char *signal,
+weechat_lua_api_hook_signal_cb (const void *pointer, void *data,
+ const char *signal,
const char *type_data, void *signal_data)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
static char str_value[64];
int *rc, ret, free_needed;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (signal) ? (char *)signal : empty_arg;
free_needed = 0;
if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
@@ -2547,9 +2580,9 @@ weechat_lua_api_hook_signal_cb (void *data, const char *signal,
else
func_argv[2] = empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -2629,25 +2662,28 @@ API_FUNC(hook_signal_send)
}
int
-weechat_lua_api_hook_hsignal_cb (void *data, const char *signal,
+weechat_lua_api_hook_hsignal_cb (const void *pointer, void *data,
+ const char *signal,
struct t_hashtable *hashtable)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (signal) ? (char *)signal : empty_arg;
func_argv[2] = hashtable;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ssh", func_argv);
if (!rc)
@@ -2712,25 +2748,27 @@ API_FUNC(hook_hsignal_send)
}
int
-weechat_lua_api_hook_config_cb (void *data, const char *option,
- const char *value)
+weechat_lua_api_hook_config_cb (const void *pointer, void *data,
+ const char *option, const char *value)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (option) ? (char *)option : empty_arg;
func_argv[2] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -2771,27 +2809,30 @@ API_FUNC(hook_config)
}
int
-weechat_lua_api_hook_completion_cb (void *data, const char *completion_item,
+weechat_lua_api_hook_completion_cb (const void *pointer, void *data,
+ const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[4];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg;
func_argv[2] = API_PTR2STR(buffer);
func_argv[3] = API_PTR2STR(completion);
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ssss", func_argv);
if (!rc)
@@ -2877,26 +2918,29 @@ API_FUNC(hook_completion_list_add)
}
char *
-weechat_lua_api_hook_modifier_cb (void *data, const char *modifier,
+weechat_lua_api_hook_modifier_cb (const void *pointer, void *data,
+ const char *modifier,
const char *modifier_data,
const char *string)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[4];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (modifier) ? (char *)modifier : empty_arg;
func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg;
func_argv[3] = (string) ? (char *)string : empty_arg;
- return (char *)weechat_lua_exec (script_callback->script,
+ return (char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
- script_callback->function,
+ ptr_function,
"ssss", func_argv);
}
@@ -2945,24 +2989,27 @@ API_FUNC(hook_modifier_exec)
}
const char *
-weechat_lua_api_hook_info_cb (void *data, const char *info_name,
+weechat_lua_api_hook_info_cb (const void *pointer, void *data,
+ const char *info_name,
const char *arguments)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
- return (const char *)weechat_lua_exec (script_callback->script,
+ return (const char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
}
@@ -2997,25 +3044,29 @@ API_FUNC(hook_info)
}
struct t_hashtable *
-weechat_lua_api_hook_info_hashtable_cb (void *data, const char *info_name,
+weechat_lua_api_hook_info_hashtable_cb (const void *pointer, void *data,
+ const char *info_name,
struct t_hashtable *hashtable)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = hashtable;
- return (struct t_hashtable *)weechat_lua_exec (script_callback->script,
- WEECHAT_SCRIPT_EXEC_HASHTABLE,
- script_callback->function,
- "ssh", func_argv);
+ return (struct t_hashtable *)weechat_lua_exec (
+ script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "ssh", func_argv);
}
return NULL;
@@ -3052,27 +3103,31 @@ API_FUNC(hook_info_hashtable)
}
struct t_infolist *
-weechat_lua_api_hook_infolist_cb (void *data, const char *info_name,
- void *pointer, const char *arguments)
+weechat_lua_api_hook_infolist_cb (const void *pointer, void *data,
+ const char *info_name,
+ void *obj_pointer, const char *arguments)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[4];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
struct t_infolist *result;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
- func_argv[2] = API_PTR2STR(pointer);
+ func_argv[2] = API_PTR2STR(obj_pointer);
func_argv[3] = (arguments) ? (char *)arguments : empty_arg;
- result = (struct t_infolist *)weechat_lua_exec (script_callback->script,
- WEECHAT_SCRIPT_EXEC_STRING,
- script_callback->function,
- "ssss", func_argv);
+ result = (struct t_infolist *)weechat_lua_exec (
+ script,
+ WEECHAT_SCRIPT_EXEC_STRING,
+ ptr_function,
+ "ssss", func_argv);
if (func_argv[2])
free (func_argv[2]);
@@ -3114,24 +3169,27 @@ API_FUNC(hook_infolist)
}
struct t_hashtable *
-weechat_lua_api_hook_focus_cb (void *data,
+weechat_lua_api_hook_focus_cb (const void *pointer, void *data,
struct t_hashtable *info)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = info;
- return (struct t_hashtable *)weechat_lua_exec (script_callback->script,
- WEECHAT_SCRIPT_EXEC_HASHTABLE,
- script_callback->function,
- "sh", func_argv);
+ return (struct t_hashtable *)weechat_lua_exec (
+ script,
+ WEECHAT_SCRIPT_EXEC_HASHTABLE,
+ ptr_function,
+ "sh", func_argv);
}
return NULL;
@@ -3187,9 +3245,7 @@ API_FUNC(unhook)
hook = lua_tostring (L, -1);
- plugin_script_api_unhook (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(hook));
+ weechat_unhook (API_STR2PTR(hook));
API_RETURN_OK;
}
@@ -3198,31 +3254,34 @@ API_FUNC(unhook_all)
{
API_INIT_FUNC(1, "unhook_all", API_RETURN_ERROR);
- plugin_script_api_unhook_all (weechat_lua_plugin, lua_current_script);
+ weechat_unhook_all_plugin (lua_current_script->name);
API_RETURN_OK;
}
int
-weechat_lua_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer,
+weechat_lua_api_buffer_input_data_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer,
const char *input_data)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(buffer);
func_argv[2] = (input_data) ? (char *)input_data : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (!rc)
@@ -3242,23 +3301,26 @@ weechat_lua_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer,
}
int
-weechat_lua_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
+weechat_lua_api_buffer_close_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[2];
char empty_arg[1] = { '\0' };
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(buffer);
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ss", func_argv);
if (!rc)
@@ -3370,9 +3432,7 @@ API_FUNC(buffer_close)
buffer = lua_tostring (L, -1);
- plugin_script_api_buffer_close (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(buffer));
+ weechat_buffer_close (API_STR2PTR(buffer));
API_RETURN_OK;
}
@@ -3931,31 +3991,34 @@ API_FUNC(bar_item_search)
}
char *
-weechat_lua_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item,
+weechat_lua_api_bar_item_build_cb (const void *pointer, void *data,
+ struct t_gui_bar_item *item,
struct t_gui_window *window,
struct t_gui_buffer *buffer,
struct t_hashtable *extra_info)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[5];
char empty_arg[1] = { '\0' }, *ret;
+ const char *ptr_function, *ptr_data;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
- if (strncmp (script_callback->function, "(extra)", 7) == 0)
+ if (strncmp (ptr_function, "(extra)", 7) == 0)
{
/* new callback: data, item, window, buffer, extra_info */
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(item);
func_argv[2] = API_PTR2STR(window);
func_argv[3] = API_PTR2STR(buffer);
func_argv[4] = extra_info;
- ret = (char *)weechat_lua_exec (script_callback->script,
+ ret = (char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
- script_callback->function + 7,
+ ptr_function + 7,
"ssssh", func_argv);
if (func_argv[1])
@@ -3968,13 +4031,13 @@ weechat_lua_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item,
else
{
/* old callback: data, item, window */
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(item);
func_argv[2] = API_PTR2STR(window);
- ret = (char *)weechat_lua_exec (script_callback->script,
+ ret = (char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
- script_callback->function,
+ ptr_function,
"sss", func_argv);
if (func_argv[1])
@@ -4037,9 +4100,7 @@ API_FUNC(bar_item_remove)
item = lua_tostring (L, -1);
- plugin_script_api_bar_item_remove (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(item));
+ weechat_bar_item_remove (API_STR2PTR(item));
API_RETURN_OK;
}
@@ -4887,69 +4948,33 @@ API_FUNC(hdata_get_string)
API_RETURN_STRING(result);
}
-API_FUNC(upgrade_new)
-{
- const char *filename;
- char *result;
- int write;
-
- API_INIT_FUNC(1, "upgrade_new", API_RETURN_EMPTY);
- if (lua_gettop (L) < 2)
- API_WRONG_ARGS(API_RETURN_EMPTY);
-
- filename = lua_tostring (L, -2);
- write = lua_tonumber (L, -1);
-
- result = API_PTR2STR(weechat_upgrade_new (filename, write));
-
- API_RETURN_STRING_FREE(result);
-}
-
-API_FUNC(upgrade_write_object)
-{
- const char *upgrade_file, *infolist;
- int object_id, rc;
-
- API_INIT_FUNC(1, "upgrade_write_object", API_RETURN_INT(0));
- if (lua_gettop (L) < 3)
- API_WRONG_ARGS(API_RETURN_INT(0));
-
- upgrade_file = lua_tostring (L, -3);
- object_id = lua_tonumber (L, -2);
- infolist = lua_tostring (L, -1);
-
- rc = weechat_upgrade_write_object (API_STR2PTR(upgrade_file),
- object_id,
- API_STR2PTR(infolist));
-
- API_RETURN_INT(rc);
-}
-
int
-weechat_lua_api_upgrade_read_cb (void *data,
+weechat_lua_api_upgrade_read_cb (const void *pointer, void *data,
struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist)
{
- struct t_plugin_script_cb *script_callback;
+ struct t_plugin_script *script;
void *func_argv[4];
char empty_arg[1] = { '\0' }, str_object_id[32];
+ const char *ptr_function, *ptr_data;
int *rc, ret;
- script_callback = (struct t_plugin_script_cb *)data;
+ script = (struct t_plugin_script *)pointer;
+ plugin_script_get_function_and_data (data, &ptr_function, &ptr_data);
- if (script_callback && script_callback->function && script_callback->function[0])
+ if (ptr_function && ptr_function[0])
{
snprintf (str_object_id, sizeof (str_object_id), "%d", object_id);
- func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
+ func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = API_PTR2STR(upgrade_file);
func_argv[2] = str_object_id;
func_argv[3] = API_PTR2STR(infolist);
- rc = (int *) weechat_lua_exec (script_callback->script,
+ rc = (int *) weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
- script_callback->function,
+ ptr_function,
"ssss", func_argv);
if (!rc)
@@ -4970,25 +4995,63 @@ weechat_lua_api_upgrade_read_cb (void *data,
return WEECHAT_RC_ERROR;
}
+API_FUNC(upgrade_new)
+{
+ const char *filename, *function, *data;
+ char *result;
+
+ API_INIT_FUNC(1, "upgrade_new", API_RETURN_EMPTY);
+ if (lua_gettop (L) < 3)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ filename = lua_tostring (L, -3);
+ function = lua_tostring (L, -2);
+ data = lua_tostring (L, -1);
+
+ result = API_PTR2STR(
+ plugin_script_api_upgrade_new (
+ weechat_lua_plugin,
+ lua_current_script,
+ filename,
+ &weechat_lua_api_upgrade_read_cb,
+ function,
+ data));
+
+ API_RETURN_STRING_FREE(result);
+}
+
+API_FUNC(upgrade_write_object)
+{
+ const char *upgrade_file, *infolist;
+ int object_id, rc;
+
+ API_INIT_FUNC(1, "upgrade_write_object", API_RETURN_INT(0));
+ if (lua_gettop (L) < 3)
+ API_WRONG_ARGS(API_RETURN_INT(0));
+
+ upgrade_file = lua_tostring (L, -3);
+ object_id = lua_tonumber (L, -2);
+ infolist = lua_tostring (L, -1);
+
+ rc = weechat_upgrade_write_object (API_STR2PTR(upgrade_file),
+ object_id,
+ API_STR2PTR(infolist));
+
+ API_RETURN_INT(rc);
+}
+
API_FUNC(upgrade_read)
{
- const char *upgrade_file, *function, *data;
+ const char *upgrade_file;
int rc;
API_INIT_FUNC(1, "upgrade_read", API_RETURN_INT(0));
- if (lua_gettop (L) < 3)
+ if (lua_gettop (L) < 1)
API_WRONG_ARGS(API_RETURN_INT(0));
- upgrade_file = lua_tostring (L, -3);
- function = lua_tostring (L, -2);
- data = lua_tostring (L, -1);
+ upgrade_file = lua_tostring (L, -1);
- rc = plugin_script_api_upgrade_read (weechat_lua_plugin,
- lua_current_script,
- API_STR2PTR(upgrade_file),
- &weechat_lua_api_upgrade_read_cb,
- function,
- data);
+ rc = weechat_upgrade_read (API_STR2PTR(upgrade_file));
API_RETURN_INT(rc);
}
diff --git a/src/plugins/lua/weechat-lua-api.h b/src/plugins/lua/weechat-lua-api.h
index 3227967dd..5143a5041 100644
--- a/src/plugins/lua/weechat-lua-api.h
+++ b/src/plugins/lua/weechat-lua-api.h
@@ -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 */
diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c
index e20eaa912..321d69c83 100644
--- a/src/plugins/lua/weechat-lua.c
+++ b/src/plugins/lua/weechat-lua.c
@@ -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;
@@ -806,37 +818,20 @@ weechat_lua_signal_debug_libs_cb (void *data, const char *signal,
}
/*
- * 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;