1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 12:56:37 +02:00

Add data string argument in all callbacks of script API, display script name in error messages for scripts

This commit is contained in:
Sebastien Helleu
2009-05-02 16:17:31 +02:00
parent a09fc84726
commit 5f1c0c8254
28 changed files with 3512 additions and 2754 deletions
File diff suppressed because it is too large Load Diff
+7 -1
View File
@@ -113,6 +113,12 @@ weechat_lua_exec (struct t_plugin_script *script,
argc = 7;
lua_pushstring (lua_current_interpreter,
argv[6]);
if (argv[7])
{
argc = 8;
lua_pushstring (lua_current_interpreter,
argv[7]);
}
}
}
}
@@ -145,7 +151,7 @@ weechat_lua_exec (struct t_plugin_script *script,
}
else
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS(function);
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, function);
lua_current_script = old_lua_current_script;
return NULL;
}
+2
View File
@@ -23,6 +23,8 @@
#define weechat_plugin weechat_lua_plugin
#define LUA_PLUGIN_NAME "lua"
#define LUA_CURRENT_SCRIPT_NAME ((lua_current_script) ? lua_current_script->name : "-")
extern struct t_weechat_plugin *weechat_lua_plugin;
extern int lua_quiet;
File diff suppressed because it is too large Load Diff
+2
View File
@@ -23,6 +23,8 @@
#define weechat_plugin weechat_perl_plugin
#define PERL_PLUGIN_NAME "perl"
#define PERL_CURRENT_SCRIPT_NAME ((perl_current_script) ? perl_current_script->name : "-")
extern struct t_weechat_plugin *weechat_perl_plugin;
extern int perl_quiet;
File diff suppressed because it is too large Load Diff
+16 -5
View File
@@ -120,11 +120,22 @@ weechat_python_exec (struct t_plugin_script *script,
{
if (argv[6])
{
rc = PyObject_CallFunction (evFunc, "sssssss",
argv[0], argv[1],
argv[2], argv[3],
argv[4], argv[5],
argv[6]);
if (argv[7])
{
rc = PyObject_CallFunction (evFunc, "ssssssss",
argv[0], argv[1],
argv[2], argv[3],
argv[4], argv[5],
argv[6], argv[7]);
}
else
{
rc = PyObject_CallFunction (evFunc, "sssssss",
argv[0], argv[1],
argv[2], argv[3],
argv[4], argv[5],
argv[6]);
}
}
else
{
@@ -23,6 +23,8 @@
#define weechat_plugin weechat_python_plugin
#define PYTHON_PLUGIN_NAME "python"
#define PYTHON_CURRENT_SCRIPT_NAME ((python_current_script) ? python_current_script->name : "-")
extern struct t_weechat_plugin *weechat_python_plugin;
extern int python_quiet;
File diff suppressed because it is too large Load Diff
+25 -9
View File
@@ -148,15 +148,31 @@ weechat_ruby_exec (struct t_plugin_script *script,
{
if (argv[6])
{
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
&ruby_error, 7,
rb_str_new2(argv[0]),
rb_str_new2(argv[1]),
rb_str_new2(argv[2]),
rb_str_new2(argv[3]),
rb_str_new2(argv[4]),
rb_str_new2(argv[5]),
rb_str_new2(argv[6]));
if (argv[7])
{
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
&ruby_error, 8,
rb_str_new2(argv[0]),
rb_str_new2(argv[1]),
rb_str_new2(argv[2]),
rb_str_new2(argv[3]),
rb_str_new2(argv[4]),
rb_str_new2(argv[5]),
rb_str_new2(argv[6]),
rb_str_new2(argv[7]));
}
else
{
rc = rb_protect_funcall ((VALUE) script->interpreter, rb_intern(function),
&ruby_error, 7,
rb_str_new2(argv[0]),
rb_str_new2(argv[1]),
rb_str_new2(argv[2]),
rb_str_new2(argv[3]),
rb_str_new2(argv[4]),
rb_str_new2(argv[5]),
rb_str_new2(argv[6]));
}
}
else
{
+2
View File
@@ -23,6 +23,8 @@
#define weechat_plugin weechat_ruby_plugin
#define RUBY_PLUGIN_NAME "ruby"
#define RUBY_CURRENT_SCRIPT_NAME ((ruby_current_script) ? ruby_current_script->name : "-")
extern struct t_weechat_plugin *weechat_ruby_plugin;
extern int ruby_quiet;
+101 -86
View File
@@ -55,7 +55,8 @@ script_api_config_new (struct t_weechat_plugin *weechat_plugin,
const char *name,
int (*callback_reload)(void *data,
struct t_config_file *config_file),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_config_file *new_config_file;
@@ -75,8 +76,7 @@ script_api_config_new (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->config_file = new_config_file;
script_callback_add (script, new_script_callback);
@@ -107,25 +107,30 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
const char *option_name,
const char *value),
const char *function_read,
const char *data_read,
void (*callback_write)(void *data,
struct t_config_file *config_file,
const char *section_name),
const char *function_write,
const char *data_write,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
const char *section_name),
const char *function_write_default,
const char *data_write_default,
int (*callback_create_option)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value),
const char *function_create_option,
const char *data_create_option,
int (*callback_delete_option)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
struct t_config_option *option),
const char *function_delete_option)
const char *function_delete_option,
const char *data_delete_option)
{
struct t_script_callback *new_script_callback1, *new_script_callback2;
struct t_script_callback *new_script_callback3, *new_script_callback4;
@@ -288,8 +293,8 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback1)
{
new_script_callback1->script = script;
new_script_callback1->function = strdup (function_read);
script_callback_init (new_script_callback1, script,
function_read, data_read);
new_script_callback1->config_file = config_file;
new_script_callback1->config_section = new_section;
script_callback_add (script, new_script_callback1);
@@ -297,8 +302,8 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback2)
{
new_script_callback2->script = script;
new_script_callback2->function = strdup (function_write);
script_callback_init (new_script_callback2, script,
function_write, data_write);
new_script_callback2->config_file = config_file;
new_script_callback2->config_section = new_section;
script_callback_add (script, new_script_callback2);
@@ -306,8 +311,8 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback3)
{
new_script_callback3->script = script;
new_script_callback3->function = strdup (function_write_default);
script_callback_init (new_script_callback3, script,
function_write_default, data_write_default);
new_script_callback3->config_file = config_file;
new_script_callback3->config_section = new_section;
script_callback_add (script, new_script_callback3);
@@ -315,8 +320,8 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback4)
{
new_script_callback4->script = script;
new_script_callback4->function = strdup (function_create_option);
script_callback_init (new_script_callback4, script,
function_create_option, data_create_option);
new_script_callback4->config_file = config_file;
new_script_callback4->config_section = new_section;
script_callback_add (script, new_script_callback4);
@@ -324,8 +329,8 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback5)
{
new_script_callback5->script = script;
new_script_callback5->function = strdup (function_delete_option);
script_callback_init (new_script_callback5, script,
function_delete_option, data_delete_option);
new_script_callback5->config_file = config_file;
new_script_callback5->config_section = new_section;
script_callback_add (script, new_script_callback5);
@@ -354,12 +359,15 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
struct t_config_option *option,
const char *value),
const char *function_check_value,
const char *data_check_value,
void (*callback_change)(void *data,
struct t_config_option *option),
const char *function_change,
const char *data_change,
void (*callback_delete)(void *data,
struct t_config_option *option),
const char *function_delete)
const char *function_delete,
const char *data_delete)
{
struct t_script_callback *new_script_callback1, *new_script_callback2;
struct t_script_callback *new_script_callback3;
@@ -445,8 +453,8 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback1)
{
new_script_callback1->script = script;
new_script_callback1->function = strdup (function_check_value);
script_callback_init (new_script_callback1, script,
function_check_value, data_check_value);
new_script_callback1->config_file = config_file;
new_script_callback1->config_section = section;
new_script_callback1->config_option = new_option;
@@ -455,8 +463,8 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback2)
{
new_script_callback2->script = script;
new_script_callback2->function = strdup (function_change);
script_callback_init (new_script_callback2, script,
function_change, data_change);
new_script_callback2->config_file = config_file;
new_script_callback2->config_section = section;
new_script_callback2->config_option = new_option;
@@ -465,8 +473,8 @@ script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback3)
{
new_script_callback3->script = script;
new_script_callback3->function = strdup (function_delete);
script_callback_init (new_script_callback3, script,
function_delete, data_delete);
new_script_callback3->config_file = config_file;
new_script_callback3->config_section = section;
new_script_callback3->config_option = new_option;
@@ -723,7 +731,8 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer,
int argc, char **argv,
char **argv_eol),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -741,9 +750,8 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
free (new_script_callback);
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -763,7 +771,8 @@ script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
const char *command),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -781,8 +790,7 @@ script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -799,8 +807,10 @@ struct t_hook *
script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
int interval, int align_second, int max_calls,
int (*callback)(void *data, int remaining_calls),
const char *function)
int (*callback)(void *data,
int remaining_calls),
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -818,8 +828,7 @@ script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -838,11 +847,12 @@ script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
int fd, int flag_read, int flag_write,
int flag_exception,
int (*callback)(void *data, int fd),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
@@ -856,8 +866,7 @@ script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -880,7 +889,8 @@ script_api_hook_process (struct t_weechat_plugin *weechat_plugin,
int return_code,
const char *stdout,
const char *stderr),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -889,8 +899,7 @@ script_api_hook_process (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback)
return NULL;
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
script_callback_add (script, new_script_callback);
new_hook = weechat_hook_process (command, timeout, callback,
@@ -921,7 +930,8 @@ script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
int (*callback)(void *data, int status,
const char *error,
const char *ip_address),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -940,8 +950,7 @@ script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -966,7 +975,8 @@ script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
int displayed, int highlight,
const char *prefix,
const char *message),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -984,8 +994,7 @@ script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -1005,7 +1014,8 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
int (*callback)(void *data, const char *signal,
const char *type_data,
void *signal_data),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -1022,8 +1032,7 @@ script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -1042,7 +1051,8 @@ script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
const char *option,
int (*callback)(void *data, const char *option,
const char *value),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -1059,8 +1069,7 @@ script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -1082,7 +1091,8 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -1100,8 +1110,7 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -1121,7 +1130,8 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
char *(*callback)(void *data, const char *modifier,
const char *modifier_data,
const char *string),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -1138,8 +1148,7 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -1160,7 +1169,8 @@ script_api_hook_info (struct t_weechat_plugin *weechat_plugin,
const char *(*callback)(void *data,
const char *info_name,
const char *arguments),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -1178,8 +1188,7 @@ script_api_hook_info (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -1201,7 +1210,8 @@ script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin,
const char *infolist_name,
void *pointer,
const char *arguments),
const char *function)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_hook *new_hook;
@@ -1219,8 +1229,7 @@ script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin,
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->hook = new_hook;
script_callback_add (script, new_script_callback);
@@ -1288,9 +1297,11 @@ script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer,
const char *input_data),
const char *function_input,
const char *data_input,
int (*close_callback)(void *data,
struct t_gui_buffer *buffer),
const char *function_close)
const char *function_close,
const char *data_close)
{
struct t_script_callback *new_script_callback_input;
struct t_script_callback *new_script_callback_close;
@@ -1350,26 +1361,31 @@ script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
if (new_script_callback_input)
{
new_script_callback_input->script = script;
new_script_callback_input->function = strdup (function_input);
script_callback_init (new_script_callback_input,
script, function_input, data_input);
new_script_callback_input->buffer = new_buffer;
script_callback_add (script, new_script_callback_input);
}
if (new_script_callback_close)
{
new_script_callback_close->script = script;
new_script_callback_close->function = strdup (function_close);
script_callback_init (new_script_callback_close,
script, function_close, data_close);
new_script_callback_close->buffer = new_buffer;
script_callback_add (script, new_script_callback_close);
}
/* used when upgrading weechat, to set callbacks */
weechat_buffer_set (new_buffer, "localvar_set_script_name",
script->name);
weechat_buffer_set (new_buffer, "localvar_set_script_input_cb",
function_input);
weechat_buffer_set (new_buffer, "localvar_set_script_input_cb_data",
data_input);
weechat_buffer_set (new_buffer, "localvar_set_script_close_cb",
function_close);
weechat_buffer_set (new_buffer, "localvar_set_script_close_cb_data",
data_close);
return new_buffer;
}
@@ -1413,7 +1429,8 @@ script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin,
char *(*build_callback)(void *data,
struct t_gui_bar_item *item,
struct t_gui_window *window),
const char *function_build)
const char *function,
const char *data)
{
struct t_script_callback *new_script_callback;
struct t_gui_bar_item *new_item;
@@ -1422,14 +1439,12 @@ script_api_bar_item_new (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback)
return NULL;
new_script_callback->script = script;
new_script_callback->function = (function_build && function_build[0]) ?
strdup (function_build) : NULL;
script_callback_init (new_script_callback, script, function, data);
new_item = weechat_bar_item_new (name,
(function_build && function_build[0]) ?
(function && function[0]) ?
build_callback : NULL,
(function_build && function_build[0]) ?
(function && function[0]) ?
new_script_callback : NULL);
if (!new_item)
{
@@ -1589,28 +1604,28 @@ script_api_upgrade_read (struct t_weechat_plugin *weechat_plugin,
struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist),
const char *function_read)
const char *function,
const char *data)
{
struct t_script_callback *script_callback;
struct t_script_callback *new_script_callback;
int rc;
if (!function_read || !function_read[0])
if (!function || !function[0])
return 0;
script_callback = script_callback_alloc ();
if (!script_callback)
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return 0;
script_callback->script = script;
script_callback->function = strdup (function_read);
script_callback->upgrade_file = upgrade_file;
script_callback_add (script, script_callback);
script_callback_init (new_script_callback, script, function, data);
new_script_callback->upgrade_file = upgrade_file;
script_callback_add (script, new_script_callback);
rc = weechat_upgrade_read (upgrade_file,
callback_read,
script_callback);
new_script_callback);
script_callback_remove (script, script_callback);
script_callback_remove (script, new_script_callback);
return rc;
}
+45 -19
View File
@@ -26,7 +26,8 @@ extern struct t_config_file *script_api_config_new (struct t_weechat_plugin *wee
const char *name,
int (*callback_reload)(void *data,
struct t_config_file *config_file),
const char *function);
const char *function,
const char *data);
extern struct t_config_section *script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
@@ -39,25 +40,30 @@ extern struct t_config_section *script_api_config_new_section (struct t_weechat_
const char *option_name,
const char *value),
const char *function_read,
const char *data_read,
void (*callback_write)(void *data,
struct t_config_file *config_file,
const char *section_name),
const char *function_write,
const char *data_write,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
const char *section_name),
const char *function_write_default,
const char *data_write_default,
int (*callback_create_option)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value),
const char *function_create_option,
const char *data_create_option,
int (*callback_delete_option)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
struct t_config_option *option),
const char *function_delete_option);
const char *function_delete_option,
const char *data_delete_option);
extern struct t_config_option *script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
@@ -74,12 +80,15 @@ extern struct t_config_option *script_api_config_new_option (struct t_weechat_pl
struct t_config_option *option,
const char *value),
const char *function_check_value,
const char *data_check_value,
void (*callback_change)(void *data,
struct t_config_option *option),
const char *function_change,
const char *data_change,
void (*callback_delete)(void *data,
struct t_config_option *option),
const char *function_delete);
const char *function_delete,
const char *data_delete);
extern void script_api_config_option_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_option *option);
@@ -117,27 +126,31 @@ extern struct t_hook *script_api_hook_command (struct t_weechat_plugin *weechat_
struct t_gui_buffer *buffer,
int argc, char **argv,
char **argv_eol),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_command_run (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *command,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
const char *command),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_timer (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
int interval, int align_second,
int max_calls,
int (*callback)(void *data,
int remaining_calls),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_fd (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
int fd, int flag_read,
int flag_write, int flag_exception,
int (*callback)(void *data, int fd),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_process (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *command,
@@ -147,7 +160,8 @@ extern struct t_hook *script_api_hook_process (struct t_weechat_plugin *weechat_
int return_code,
const char *stdout,
const char *stderr),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_connect (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *proxy,
@@ -161,7 +175,8 @@ extern struct t_hook *script_api_hook_connect (struct t_weechat_plugin *weechat_
int status,
const char *error,
const char *ip_address),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_print (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
@@ -177,7 +192,8 @@ extern struct t_hook *script_api_hook_print (struct t_weechat_plugin *weechat_pl
int highlight,
const char *prefix,
const char *message),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_signal (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *signal,
@@ -185,14 +201,16 @@ extern struct t_hook *script_api_hook_signal (struct t_weechat_plugin *weechat_p
const char *signal,
const char *type_data,
void *signal_data),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_config (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *option,
int (*callback)(void *data,
const char *option,
const char *value),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *completion,
@@ -201,7 +219,8 @@ extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weech
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *modifier,
@@ -209,7 +228,8 @@ extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat
const char *modifier,
const char *modifier_data,
const char *string),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_info (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *info_name,
@@ -217,7 +237,8 @@ extern struct t_hook *script_api_hook_info (struct t_weechat_plugin *weechat_plu
const char *(*callback)(void *data,
const char *info_name,
const char *arguments),
const char *function);
const char *function,
const char *data);
extern struct t_hook *script_api_hook_infolist (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *infolist_name,
@@ -226,7 +247,8 @@ extern struct t_hook *script_api_hook_infolist (struct t_weechat_plugin *weechat
const char *infolist_name,
void *pointer,
const char *arguments),
const char *function);
const char *function,
const char *data);
extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);
@@ -238,9 +260,11 @@ extern struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weec
struct t_gui_buffer *buffer,
const char *input_data),
const char *function_input,
const char *data_input,
int (*close_callback)(void *data,
struct t_gui_buffer *buffer),
const char *function_close);
const char *function_close,
const char *data_close);
extern void script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer);
@@ -250,7 +274,8 @@ extern struct t_gui_bar_item *script_api_bar_item_new (struct t_weechat_plugin *
char *(*build_callback)(void *data,
struct t_gui_bar_item *item,
struct t_gui_window *window),
const char *function_build);
const char *function,
const char *data);
extern void script_api_bar_item_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_bar_item *item);
@@ -274,6 +299,7 @@ extern int script_api_upgrade_read (struct t_weechat_plugin *weechat_plugin,
struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist),
const char *function_read);
const char *function,
const char *data);
#endif /* script-api.h */
+23
View File
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "script.h"
@@ -41,6 +42,7 @@ script_callback_alloc ()
{
new_script_callback->script = NULL;
new_script_callback->function = NULL;
new_script_callback->data = NULL;
new_script_callback->config_file = NULL;
new_script_callback->config_section = NULL;
new_script_callback->config_option = NULL;
@@ -54,6 +56,24 @@ script_callback_alloc ()
return NULL;
}
/*
* script_callback_init: initialize callback with script, function and data
*/
void
script_callback_init (struct t_script_callback *script_callback,
struct t_plugin_script *script,
const char *function,
const char *data)
{
if (script_callback)
{
script_callback->script = script;
script_callback->function = (function) ? strdup (function) : NULL;
script_callback->data = (data) ? strdup (data) : NULL;
}
}
/*
* script_callback_add: add a callback to list
*/
@@ -78,6 +98,8 @@ script_callback_free_data (struct t_script_callback *script_callback)
{
if (script_callback->function)
free (script_callback->function);
if (script_callback->data)
free (script_callback->data);
}
/*
@@ -128,6 +150,7 @@ script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
weechat_log_printf (" [callback (addr:0x%lx)]", script_callback);
weechat_log_printf (" script. . . . . . . : 0x%lx", script_callback->script);
weechat_log_printf (" function. . . . . . : '%s'", script_callback->function);
weechat_log_printf (" data. . . . . . . . : '%s'", script_callback->data);
weechat_log_printf (" config_file . . . . : 0x%lx", script_callback->config_file);
weechat_log_printf (" config_section. . . : 0x%lx", script_callback->config_section);
weechat_log_printf (" config_option . . . : 0x%lx", script_callback->config_option);
+5
View File
@@ -23,6 +23,7 @@ struct t_script_callback
{
void *script; /* pointer to script */
char *function; /* script function called */
char *data; /* data string for callback */
struct t_config_file *config_file; /* not NULL for config file */
struct t_config_section *config_section; /* not NULL for config section */
struct t_config_option *config_option; /* not NULL for config option */
@@ -35,6 +36,10 @@ struct t_script_callback
};
extern struct t_script_callback *script_callback_alloc ();
extern void script_callback_init (struct t_script_callback *script_callback,
struct t_plugin_script *script,
const char *function,
const char *data);
extern void script_callback_add (struct t_plugin_script *script,
struct t_script_callback *callback);
extern void script_callback_free_data (struct t_script_callback *script_callback);
+10 -5
View File
@@ -94,7 +94,8 @@ script_upgrade_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
{
struct t_infolist *infolist;
struct t_gui_buffer *ptr_buffer;
const char *script_name, *script_input_cb, *script_close_cb;
const char *script_name, *script_input_cb, *script_input_cb_data;
const char *script_close_cb, *script_close_cb_data;
struct t_plugin_script *ptr_script;
struct t_script_callback *new_script_callback_input;
struct t_script_callback *new_script_callback_close;
@@ -122,8 +123,10 @@ script_upgrade_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
new_script_callback_input = script_callback_alloc ();
if (new_script_callback_input)
{
new_script_callback_input->script = ptr_script;
new_script_callback_input->function = strdup (script_input_cb);
script_callback_init (new_script_callback_input,
ptr_script,
script_input_cb,
script_input_cb_data);
new_script_callback_input->buffer = ptr_buffer;
script_callback_add (ptr_script,
new_script_callback_input);
@@ -140,8 +143,10 @@ script_upgrade_set_buffer_callbacks (struct t_weechat_plugin *weechat_plugin,
new_script_callback_close = script_callback_alloc ();
if (new_script_callback_close)
{
new_script_callback_close->script = ptr_script;
new_script_callback_close->function = strdup (script_close_cb);
script_callback_init (new_script_callback_close,
ptr_script,
script_close_cb,
script_close_cb_data);
new_script_callback_close->buffer = ptr_buffer;
script_callback_add (ptr_script,
new_script_callback_close);
+10 -6
View File
@@ -23,19 +23,23 @@
#define WEECHAT_SCRIPT_EXEC_INT 1
#define WEECHAT_SCRIPT_EXEC_STRING 2
#define WEECHAT_SCRIPT_MSG_NOT_INITIALIZED(__function) \
#define WEECHAT_SCRIPT_MSG_NOT_INIT(__current_script, \
__function) \
weechat_printf (NULL, \
weechat_gettext("%s%s: unable to call function " \
"\"%s\", script is not " \
"initialized"), \
"initialized (script: %s)"), \
weechat_prefix ("error"), weechat_plugin->name, \
__function)
#define WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS(__function) \
__function, \
(__current_script) ? __current_script : "-");
#define WEECHAT_SCRIPT_MSG_WRONG_ARGS(__current_script, \
__function) \
weechat_printf (NULL, \
weechat_gettext("%s%s: wrong arguments for " \
"function \"%s\""), \
"function \"%s\" (script: %s)"), \
weechat_prefix ("error"), weechat_plugin->name, \
__function)
__function, \
(__current_script) ? __current_script : "-");
struct t_plugin_script
{
File diff suppressed because it is too large Load Diff
+2
View File
@@ -23,6 +23,8 @@
#define weechat_plugin weechat_tcl_plugin
#define TCL_PLUGIN_NAME "tcl"
#define TCL_CURRENT_SCRIPT_NAME ((tcl_current_script) ? tcl_current_script->name : "-")
extern struct t_weechat_plugin *weechat_tcl_plugin;
extern int tcl_quiet;