mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 04:46:37 +02:00
Migration of Lua plugin to new API
This commit is contained in:
@@ -20,6 +20,9 @@ libdir = ${weechat_libdir}/plugins
|
||||
|
||||
lib_LTLIBRARIES = lua.la
|
||||
|
||||
lua_la_SOURCES = lua.c
|
||||
lua_la_SOURCES = weechat-lua.c \
|
||||
weechat-lua.h \
|
||||
weechat-lua-api.c \
|
||||
weechat-lua-api.h
|
||||
lua_la_LDFLAGS = -module
|
||||
lua_la_LIBADD = ../lib_weechat_plugins_scripts.la $(LUA_LFLAGS)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __WEECHAT_LUA_API_H
|
||||
#define __WEECHAT_LUA_API_H 1
|
||||
|
||||
extern struct luaL_reg weechat_lua_api_funcs[];
|
||||
|
||||
#endif /* weechat-lua.h */
|
||||
@@ -0,0 +1,598 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* weechat-lua.c: Lua plugin for WeeChat */
|
||||
|
||||
#undef _
|
||||
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <stdarg.h>
|
||||
//#include <time.h>
|
||||
//#include <sys/socket.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../script.h"
|
||||
#include "weechat-lua.h"
|
||||
#include "weechat-lua-api.h"
|
||||
|
||||
|
||||
WEECHAT_PLUGIN_NAME("lua");
|
||||
WEECHAT_PLUGIN_DESCRIPTION("Lua plugin for WeeChat");
|
||||
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
|
||||
WEECHAT_PLUGIN_VERSION("0.1");
|
||||
WEECHAT_PLUGIN_LICENSE("GPL");
|
||||
|
||||
struct t_weechat_plugin *weechat_lua_plugin;
|
||||
|
||||
struct t_plugin_script *lua_scripts = NULL;
|
||||
struct t_plugin_script *lua_current_script = NULL;
|
||||
char *lua_current_script_filename = NULL;
|
||||
lua_State *lua_current_interpreter = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* weechat_lua_exec: execute a Lua script
|
||||
*/
|
||||
|
||||
void *
|
||||
weechat_lua_exec (struct t_plugin_script *script,
|
||||
int ret_type, char *function, char **argv)
|
||||
{
|
||||
void *ret_value;
|
||||
int argc, *ret_i;
|
||||
|
||||
lua_current_interpreter = script->interpreter;
|
||||
|
||||
lua_getglobal (lua_current_interpreter, function);
|
||||
lua_current_script = script;
|
||||
|
||||
if (argv && argv[0])
|
||||
{
|
||||
lua_pushstring (lua_current_interpreter, argv[0]);
|
||||
argc = 1;
|
||||
if (argv[1])
|
||||
{
|
||||
argc = 2;
|
||||
lua_pushstring (lua_current_interpreter, argv[1]);
|
||||
if (argv[2])
|
||||
{
|
||||
argc = 3;
|
||||
lua_pushstring (lua_current_interpreter, argv[2]);
|
||||
if (argv[3])
|
||||
{
|
||||
argc = 4;
|
||||
lua_pushstring (lua_current_interpreter, argv[3]);
|
||||
if (argv[4])
|
||||
{
|
||||
argc = 5;
|
||||
lua_pushstring (lua_current_interpreter, argv[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lua_pcall (lua_current_interpreter, argc, 1, 0) != 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to run function \"%s\""),
|
||||
weechat_prefix ("error"), "lua", function);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: %s"),
|
||||
weechat_prefix ("error"), "lua",
|
||||
lua_tostring (lua_current_interpreter, -1));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
|
||||
ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
|
||||
else if (ret_type == WEECHAT_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
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS(function);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
int
|
||||
weechat_lua_load (char *filename)
|
||||
{
|
||||
FILE *fp;
|
||||
char *weechat_lua_code = {
|
||||
"weechat_outputs = {\n"
|
||||
" write = function (self, str)\n"
|
||||
" weechat.print(\"Lua stdout/stderr : \" .. str)\n"
|
||||
" end\n"
|
||||
"}\n"
|
||||
"io.stdout = weechat_outputs\n"
|
||||
"io.stderr = weechat_outputs\n"
|
||||
};
|
||||
|
||||
if ((fp = fopen (filename, "r")) == NULL)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" not found"),
|
||||
weechat_prefix ("error"), "lua", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: loading script \"%s\""),
|
||||
weechat_prefix ("info"), "lua", filename);
|
||||
|
||||
lua_current_script = NULL;
|
||||
|
||||
lua_current_interpreter = lua_open ();
|
||||
|
||||
if (lua_current_interpreter == NULL)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to create new "
|
||||
"sub-interpreter"),
|
||||
weechat_prefix ("error"), "lua");
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LUA_VERSION_NUM /* LUA_VERSION_NUM is defined only in lua >= 5.1.0 */
|
||||
luaL_openlibs (lua_current_interpreter);
|
||||
#else
|
||||
luaopen_base (lua_current_interpreter);
|
||||
luaopen_string (lua_current_interpreter);
|
||||
luaopen_table (lua_current_interpreter);
|
||||
luaopen_math (lua_current_interpreter);
|
||||
luaopen_io (lua_current_interpreter);
|
||||
luaopen_debug (lua_current_interpreter);
|
||||
#endif
|
||||
|
||||
luaL_openlib (lua_current_interpreter, "weechat", weechat_lua_api_funcs, 0);
|
||||
|
||||
#ifdef LUA_VERSION_NUM
|
||||
if (luaL_dostring (lua_current_interpreter, weechat_lua_code) != 0)
|
||||
#else
|
||||
if (lua_dostring (lua_current_interpreter, weechat_lua_code) != 0)
|
||||
#endif
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to redirect stdout "
|
||||
"and stderr"),
|
||||
weechat_prefix ("error"), "lua");
|
||||
}
|
||||
|
||||
lua_current_script_filename = filename;
|
||||
|
||||
if (luaL_loadfile (lua_current_interpreter, filename) != 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to load file \"%s\""),
|
||||
weechat_prefix ("error"), "lua", filename);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: %s"),
|
||||
weechat_prefix ("error"), "lua",
|
||||
lua_tostring (lua_current_interpreter, -1));
|
||||
lua_close (lua_current_interpreter);
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lua_pcall (lua_current_interpreter, 0, 0, 0) != 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unable to execute file "
|
||||
"\"%s\""),
|
||||
weechat_prefix ("error"), "lua", filename);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: error: %s"),
|
||||
weechat_prefix ("error"), "lua",
|
||||
lua_tostring (lua_current_interpreter, -1));
|
||||
lua_close (lua_current_interpreter);
|
||||
fclose (fp);
|
||||
/* if script was registered, removing from list */
|
||||
if (lua_current_script)
|
||||
script_remove (weechat_lua_plugin, &lua_scripts, lua_current_script);
|
||||
return 0;
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
if (lua_current_script == NULL)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: function \"register\" not "
|
||||
"found (or failed) in file \"%s\""),
|
||||
weechat_prefix ("error"), "lua", filename);
|
||||
lua_close (lua_current_interpreter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_current_script->interpreter = (lua_State *) lua_current_interpreter;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_load_cb: callback for weechat_script_auto_load() function
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_load_cb (void *data, char *filename)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
return weechat_lua_load (filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_unload: unload a Lua script
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_lua_unload (struct t_plugin_script *script)
|
||||
{
|
||||
int *r;
|
||||
char *lua_argv[1] = { NULL };
|
||||
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unloading script \"%s\""),
|
||||
weechat_prefix ("info"), "lua", script->name);
|
||||
|
||||
if (script->shutdown_func && script->shutdown_func[0])
|
||||
{
|
||||
r = weechat_lua_exec (script,
|
||||
WEECHAT_SCRIPT_EXEC_INT,
|
||||
script->shutdown_func,
|
||||
lua_argv);
|
||||
if (r)
|
||||
free (r);
|
||||
}
|
||||
|
||||
lua_close (script->interpreter);
|
||||
|
||||
script_remove (weechat_lua_plugin, &lua_scripts, script);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_unload_name: unload a Lua script by name
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_lua_unload_name (char *name)
|
||||
{
|
||||
struct t_plugin_script *ptr_script;
|
||||
|
||||
ptr_script = script_search (weechat_lua_plugin, lua_scripts, name);
|
||||
if (ptr_script)
|
||||
{
|
||||
weechat_lua_unload (ptr_script);
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" unloaded"),
|
||||
weechat_prefix ("info"), "lua", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: script \"%s\" not loaded"),
|
||||
weechat_prefix ("error"), "lua", name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_unload_all: unload all Lua scripts
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_lua_unload_all ()
|
||||
{
|
||||
while (lua_scripts)
|
||||
{
|
||||
weechat_lua_unload (lua_scripts);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_command_cb: callback for "/lua" command
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
//int handler_found, modifier_found;
|
||||
char *path_script;
|
||||
struct t_plugin_script *ptr_script;
|
||||
//t_plugin_handler *ptr_handler;
|
||||
//t_plugin_modifier *ptr_modifier;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
/* list registered Lua scripts */
|
||||
weechat_printf (NULL, "");
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("Registered %s scripts:"),
|
||||
"lua");
|
||||
if (lua_scripts)
|
||||
{
|
||||
for (ptr_script = lua_scripts; ptr_script;
|
||||
ptr_script = ptr_script->next_script)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext (" %s v%s (%s), by %s, "
|
||||
"license %s"),
|
||||
ptr_script->name,
|
||||
ptr_script->version,
|
||||
ptr_script->description,
|
||||
ptr_script->author,
|
||||
ptr_script->license);
|
||||
}
|
||||
}
|
||||
else
|
||||
weechat_printf (NULL, weechat_gettext (" (none)"));
|
||||
|
||||
/*
|
||||
// list Lua message handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua message handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_MESSAGE)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " IRC(%s) => Lua(%s)",
|
||||
ptr_handler->irc_command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua command handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua command handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_COMMAND)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " /%s => Lua(%s)",
|
||||
ptr_handler->command,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua timer handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua timer handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_TIMER)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %d seconds => Lua(%s)",
|
||||
ptr_handler->interval,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua keyboard handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua keyboard handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_KEYBOARD)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " Lua(%s)",
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// list Lua event handlers
|
||||
plugin->print_server (plugin, "");
|
||||
plugin->print_server (plugin, "Lua event handlers:");
|
||||
handler_found = 0;
|
||||
for (ptr_handler = plugin->handlers;
|
||||
ptr_handler; ptr_handler = ptr_handler->next_handler)
|
||||
{
|
||||
if ((ptr_handler->type == PLUGIN_HANDLER_EVENT)
|
||||
&& (ptr_handler->handler_args))
|
||||
{
|
||||
handler_found = 1;
|
||||
plugin->print_server (plugin, " %s => Lua(%s)",
|
||||
ptr_handler->event,
|
||||
ptr_handler->handler_args);
|
||||
}
|
||||
}
|
||||
if (!handler_found)
|
||||
plugin->print_server (plugin, " (none)");
|
||||
|
||||
// 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)");
|
||||
*/
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "autoload") == 0)
|
||||
script_auto_load (weechat_lua_plugin,
|
||||
"lua", &weechat_lua_load_cb);
|
||||
else if (weechat_strcasecmp (argv[1], "reload") == 0)
|
||||
{
|
||||
weechat_lua_unload_all ();
|
||||
script_auto_load (weechat_lua_plugin,
|
||||
"lua", &weechat_lua_load_cb);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
weechat_lua_unload_all ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (weechat_strcasecmp (argv[1], "load") == 0)
|
||||
{
|
||||
/* load Lua script */
|
||||
path_script = script_search_full_name (weechat_lua_plugin,
|
||||
"lua", argv_eol[2]);
|
||||
weechat_lua_load ((path_script) ? path_script : argv_eol[2]);
|
||||
if (path_script)
|
||||
free (path_script);
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[1], "unload") == 0)
|
||||
{
|
||||
/* unload Lua script */
|
||||
weechat_lua_unload_name (argv_eol[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
weechat_gettext ("%s%s: unknown option for "
|
||||
"command \"%s\""),
|
||||
weechat_prefix ("error"), "lua", "lua");
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_dump_data_cb: dump Lua plugin data in WeeChat log file
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_lua_dump_data_cb (void *data, char *signal, char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
(void) signal_data;
|
||||
|
||||
script_print_log (weechat_lua_plugin, lua_scripts);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize Lua plugin
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
|
||||
weechat_lua_plugin = plugin;
|
||||
|
||||
weechat_hook_command ("lua",
|
||||
weechat_gettext ("list/load/unload Lua scripts"),
|
||||
weechat_gettext ("[load filename] | [autoload] | "
|
||||
"[reload] | [unload [script]]"),
|
||||
weechat_gettext ("filename: Lua script (file) to "
|
||||
"load\n"
|
||||
"script: script name to unload\n\n"
|
||||
"Without argument, /lua command "
|
||||
"lists all loaded Lua scripts."),
|
||||
"load|autoload|reload|unload %f",
|
||||
&weechat_lua_command_cb, NULL);
|
||||
|
||||
weechat_mkdir_home ("lua", 0644);
|
||||
weechat_mkdir_home ("lua/autoload", 0644);
|
||||
|
||||
weechat_hook_signal ("dump_data", &weechat_lua_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_lua_plugin);
|
||||
script_auto_load (weechat_lua_plugin, "lua", &weechat_lua_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_end: shutdown Lua interface
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) plugin;
|
||||
|
||||
/* unload all scripts */
|
||||
weechat_lua_unload_all ();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __WEECHAT_LUA_H
|
||||
#define __WEECHAT_LUA_H 1
|
||||
|
||||
#define weechat_plugin weechat_lua_plugin
|
||||
|
||||
extern struct t_weechat_plugin *weechat_lua_plugin;
|
||||
|
||||
extern struct t_plugin_script *lua_scripts;
|
||||
extern struct t_plugin_script *lua_current_script;
|
||||
extern char *lua_current_script_filename;
|
||||
extern lua_State *lua_current_interpreter;
|
||||
|
||||
extern void * weechat_lua_exec (struct t_plugin_script *script,
|
||||
int ret_type, char *function, char **argv);
|
||||
|
||||
#endif /* weechat-lua.h */
|
||||
@@ -45,7 +45,7 @@
|
||||
XSRETURN (1); \
|
||||
} \
|
||||
XST_mPV (0, ""); \
|
||||
XSRETURN (1);
|
||||
XSRETURN (1)
|
||||
#define PERL_RETURN_STRING_FREE(__string) \
|
||||
if (__string) \
|
||||
{ \
|
||||
@@ -54,7 +54,7 @@
|
||||
XSRETURN (1); \
|
||||
} \
|
||||
XST_mPV (0, ""); \
|
||||
XSRETURN (1);
|
||||
XSRETURN (1)
|
||||
|
||||
extern void boot_DynaLoader (pTHX_ CV* cv);
|
||||
|
||||
@@ -328,7 +328,7 @@ static XS (XS_weechat_color)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::print: print message into a buffer (current or specified one)
|
||||
* weechat::print: print message in a buffer
|
||||
*/
|
||||
|
||||
static XS (XS_weechat_print)
|
||||
@@ -828,7 +828,7 @@ static XS (XS_weechat_hook_signal)
|
||||
static XS (XS_weechat_hook_signal_send)
|
||||
{
|
||||
char *type_data;
|
||||
int int_value;
|
||||
int number;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -856,10 +856,10 @@ static XS (XS_weechat_hook_signal_send)
|
||||
}
|
||||
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0)
|
||||
{
|
||||
int_value = SvIV(ST (2));
|
||||
number = SvIV(ST (2));
|
||||
weechat_hook_signal_send (SvPV (ST (0), PL_na), /* signal */
|
||||
type_data,
|
||||
&int_value); /* signal_data */
|
||||
&number); /* signal_data */
|
||||
PERL_RETURN_OK;
|
||||
}
|
||||
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
|
||||
|
||||
@@ -730,8 +730,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
weechat_hook_signal ("dump_data", &weechat_perl_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_perl_plugin);
|
||||
script_auto_load (weechat_perl_plugin,
|
||||
"perl", &weechat_perl_load_cb);
|
||||
script_auto_load (weechat_perl_plugin, "perl", &weechat_perl_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#define PYTHON_RETURN_STRING(__string) \
|
||||
if (__string) \
|
||||
return Py_BuildValue ("s", __string); \
|
||||
return Py_BuildValue ("s", "");
|
||||
return Py_BuildValue ("s", "")
|
||||
#define PYTHON_RETURN_STRING_FREE(__string) \
|
||||
if (__string) \
|
||||
{ \
|
||||
@@ -49,7 +49,7 @@
|
||||
free (__string); \
|
||||
return object; \
|
||||
} \
|
||||
return Py_BuildValue ("s", "");
|
||||
return Py_BuildValue ("s", "")
|
||||
|
||||
|
||||
/*
|
||||
@@ -342,7 +342,7 @@ weechat_python_api_color (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_prnt: print message into a buffer (current or specified one)
|
||||
* weechat_python_api_prnt: print message in a buffer
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
@@ -900,7 +900,7 @@ static PyObject *
|
||||
weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *signal, *type_data, *signal_data, *error;
|
||||
long number;
|
||||
int number;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
@@ -920,10 +920,11 @@ weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal_send");
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
|
||||
if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
|
||||
{
|
||||
weechat_hook_signal_send (signal, type_data, signal_data);
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_INT) == 0)
|
||||
{
|
||||
@@ -933,13 +934,16 @@ weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
|
||||
{
|
||||
weechat_hook_signal_send (signal, type_data, &number);
|
||||
}
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
|
||||
{
|
||||
weechat_hook_signal_send (signal, type_data,
|
||||
script_string_to_pointer (signal_data));
|
||||
PYTHON_RETURN_OK;
|
||||
}
|
||||
PYTHON_RETURN_OK;
|
||||
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -767,8 +767,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
weechat_hook_signal ("dump_data", &weechat_python_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_python_plugin);
|
||||
script_auto_load (weechat_python_plugin,
|
||||
"python", &weechat_python_load_cb);
|
||||
script_auto_load (weechat_python_plugin, "python", &weechat_python_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#define RUBY_RETURN_STRING(__string) \
|
||||
if (__string) \
|
||||
return rb_str_new2 (__string); \
|
||||
return rb_str_new2 ("");
|
||||
return rb_str_new2 ("")
|
||||
#define RUBY_RETURN_STRING_FREE(__string) \
|
||||
if (__string) \
|
||||
{ \
|
||||
@@ -53,7 +53,7 @@
|
||||
free (__string); \
|
||||
return return_value; \
|
||||
} \
|
||||
return rb_str_new2 ("");
|
||||
return rb_str_new2 ("")
|
||||
|
||||
|
||||
/*
|
||||
@@ -402,7 +402,7 @@ weechat_ruby_api_color (VALUE class, VALUE color)
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_print: print message into a buffer (current or specified one)
|
||||
* weechat_ruby_api_print: print message in a buffer
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
@@ -1043,7 +1043,7 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
|
||||
VALUE signal_data)
|
||||
{
|
||||
char *c_signal, *c_type_data, *c_signal_data;
|
||||
int int_value;
|
||||
int number;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
@@ -1080,8 +1080,8 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
|
||||
else if (strcmp (c_type_data, WEECHAT_HOOK_SIGNAL_INT) == 0)
|
||||
{
|
||||
Check_Type (signal_data, T_STRING);
|
||||
int_value = FIX2INT (signal_data);
|
||||
weechat_hook_signal_send (c_signal, c_type_data, &int_value);
|
||||
number = FIX2INT (signal_data);
|
||||
weechat_hook_signal_send (c_signal, c_type_data, &number);
|
||||
RUBY_RETURN_OK;
|
||||
}
|
||||
else if (strcmp (c_type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
|
||||
@@ -1101,7 +1101,8 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_api_hook_config_cb (void *data, char *type, char *option, char *value)
|
||||
weechat_ruby_api_hook_config_cb (void *data, char *type, char *option,
|
||||
char *value)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
char *ruby_argv[4];
|
||||
@@ -1184,7 +1185,8 @@ weechat_ruby_api_hook_config (VALUE class, VALUE type, VALUE option, VALUE funct
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_ruby_api_hook_completion_cb (void *data, char *completion, struct t_gui_buffer *buffer,
|
||||
weechat_ruby_api_hook_completion_cb (void *data, char *completion,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_weelist *list)
|
||||
{
|
||||
struct t_script_callback *script_callback;
|
||||
@@ -1734,7 +1736,7 @@ weechat_ruby_api_nicklist_add_nick (VALUE class, VALUE buffer, VALUE group,
|
||||
script_string_to_pointer (c_group),
|
||||
c_name,
|
||||
c_color,
|
||||
prefix,
|
||||
char_prefix,
|
||||
c_prefix_color,
|
||||
c_visible);
|
||||
|
||||
|
||||
@@ -821,8 +821,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
weechat_hook_signal ("dump_data", &weechat_ruby_dump_data_cb, NULL);
|
||||
|
||||
script_init (weechat_ruby_plugin);
|
||||
script_auto_load (weechat_ruby_plugin,
|
||||
"ruby", &weechat_ruby_load_cb);
|
||||
script_auto_load (weechat_ruby_plugin, "ruby", &weechat_ruby_load_cb);
|
||||
|
||||
/* init ok */
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
Reference in New Issue
Block a user