mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 12:26:40 +02:00
add modifiers in scripts/plugins API, cleaning code in script/plugins, improve display for stdout/stderr redirections for python and ruby
This commit is contained in:
@@ -55,11 +55,14 @@ lua_State *lua_current_interpreter = NULL;
|
||||
* weechat_lua_exec: execute a Lua script
|
||||
*/
|
||||
|
||||
int
|
||||
void *
|
||||
weechat_lua_exec (t_weechat_plugin *plugin,
|
||||
t_plugin_script *script,
|
||||
int ret_type,
|
||||
char *function, char *arg1, char *arg2, char *arg3)
|
||||
{
|
||||
void *ret_value;
|
||||
int *ret_i;
|
||||
|
||||
lua_current_interpreter = script->interpreter;
|
||||
|
||||
@@ -86,10 +89,27 @@ weechat_lua_exec (t_weechat_plugin *plugin,
|
||||
plugin->print_server (plugin,
|
||||
"Lua error: %s",
|
||||
lua_tostring (lua_current_interpreter, -1));
|
||||
return PLUGIN_RC_KO;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return lua_tonumber (lua_current_interpreter, -1);
|
||||
if (ret_type == SCRIPT_EXEC_STRING)
|
||||
ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
|
||||
else if (ret_type == SCRIPT_EXEC_INT)
|
||||
{
|
||||
ret_i = (int *) malloc (sizeof(int));
|
||||
if (ret_i)
|
||||
*ret_i = lua_tonumber (lua_current_interpreter, -1);
|
||||
ret_value = ret_i;
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for function \"%s\"",
|
||||
function);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -101,9 +121,23 @@ weechat_lua_cmd_msg_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int *r;
|
||||
int ret;
|
||||
|
||||
if (argc >= 3)
|
||||
return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[2], NULL);
|
||||
{
|
||||
r = (int *) weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
SCRIPT_EXEC_INT,
|
||||
handler_args, argv[0], argv[2], NULL);
|
||||
if (r == NULL)
|
||||
ret = PLUGIN_RC_KO;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
@@ -120,9 +154,20 @@ weechat_lua_timer_handler (t_weechat_plugin *plugin,
|
||||
/* make gcc happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int *r;
|
||||
int ret;
|
||||
|
||||
return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, NULL, NULL, NULL);
|
||||
r = (int *) weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
SCRIPT_EXEC_INT,
|
||||
handler_args, NULL, NULL, NULL);
|
||||
if (r == NULL)
|
||||
ret = PLUGIN_RC_KO;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -134,9 +179,23 @@ weechat_lua_keyboard_handler (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
if (argc >= 2)
|
||||
return weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
handler_args, argv[0], argv[1], argv[2]);
|
||||
int *r;
|
||||
int ret;
|
||||
|
||||
if (argc >= 3)
|
||||
{
|
||||
r = (int *) weechat_lua_exec (plugin, (t_plugin_script *)handler_pointer,
|
||||
SCRIPT_EXEC_INT,
|
||||
handler_args, argv[0], argv[1], argv[2]);
|
||||
if (r == NULL)
|
||||
ret = PLUGIN_RC_KO;
|
||||
else
|
||||
{
|
||||
ret = *r;
|
||||
free (r);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return PLUGIN_RC_KO;
|
||||
}
|
||||
@@ -150,12 +209,12 @@ weechat_lua_modifier (t_weechat_plugin *plugin,
|
||||
int argc, char **argv,
|
||||
char *modifier_args, void *modifier_pointer)
|
||||
{
|
||||
/*if (argc >= 2)
|
||||
return weechat_lua_exec (plugin, (t_plugin_script *)modifier_pointer,
|
||||
modifier_args, argv[0], argv[1], NULL);
|
||||
if (argc >= 2)
|
||||
return (char *) weechat_lua_exec (plugin, (t_plugin_script *)modifier_pointer,
|
||||
SCRIPT_EXEC_STRING,
|
||||
modifier_args, argv[0], argv[1], NULL);
|
||||
else
|
||||
return NULL;*/
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -968,12 +1027,13 @@ weechat_lua_remove_modifier (lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
type = NULL;
|
||||
command = NULL;
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n != 2)
|
||||
if (n != 3)
|
||||
{
|
||||
lua_plugin->print_server (lua_plugin,
|
||||
"Lua error: wrong parameters for "
|
||||
@@ -2153,12 +2213,19 @@ weechat_lua_load (t_weechat_plugin *plugin, char *filename)
|
||||
void
|
||||
weechat_lua_unload (t_weechat_plugin *plugin, t_plugin_script *script)
|
||||
{
|
||||
int *r;
|
||||
|
||||
plugin->print_server (plugin,
|
||||
"Unloading Lua script \"%s\"",
|
||||
script->name);
|
||||
|
||||
if (script->shutdown_func[0])
|
||||
weechat_lua_exec (plugin, script, script->shutdown_func, NULL, NULL, NULL);
|
||||
{
|
||||
r = weechat_lua_exec (plugin, script, SCRIPT_EXEC_INT,
|
||||
script->shutdown_func, NULL, NULL, NULL);
|
||||
if (r)
|
||||
free (r);
|
||||
}
|
||||
|
||||
lua_close (script->interpreter);
|
||||
|
||||
@@ -2215,11 +2282,12 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
|
||||
int cmd_argc, char **cmd_argv,
|
||||
char *handler_args, void *handler_pointer)
|
||||
{
|
||||
int argc, handler_found;
|
||||
int argc, handler_found, modifier_found;
|
||||
char **argv, *path_script;
|
||||
t_plugin_script *ptr_script;
|
||||
t_plugin_handler *ptr_handler;
|
||||
|
||||
t_plugin_modifier *ptr_modifier;
|
||||
|
||||
/* make gcc happy */
|
||||
(void) handler_args;
|
||||
(void) handler_pointer;
|
||||
@@ -2330,7 +2398,34 @@ weechat_lua_cmd (t_weechat_plugin *plugin,
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
break;
|
||||
|
||||
/* list Lua modifiers */
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua modifiers:");
|
||||
modifier_found = 0;
|
||||
for (ptr_modifier = plugin->modifiers;
|
||||
ptr_modifier; ptr_modifier = ptr_modifier->next_modifier)
|
||||
{
|
||||
modifier_found = 1;
|
||||
if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_IN)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Lua(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_IN_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_USER)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Lua(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_USER_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
else if (ptr_modifier->type == PLUGIN_MODIFIER_IRC_OUT)
|
||||
plugin->print_server (plugin, " IRC(%s, %s) => Lua(%s)",
|
||||
ptr_modifier->command,
|
||||
PLUGIN_MODIFIER_IRC_OUT_STR,
|
||||
ptr_modifier->modifier_args);
|
||||
}
|
||||
if (!modifier_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
break;
|
||||
case 1:
|
||||
if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0)
|
||||
weechat_script_auto_load (plugin, "lua", weechat_lua_load);
|
||||
|
||||
Reference in New Issue
Block a user