1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 09:05:41 +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;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+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;