summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-01-16 10:19:25 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-01-16 10:19:25 +0100
commit697f070725bc62e4d156e3aabb5a2be93cd685e6 (patch)
tree144efa7f8f4c2b092855140807dfaf51317c72f3
parente173014aec7ee5b58d5f80e029aeef80201a04ce (diff)
downloadweechat-697f070725bc62e4d156e3aabb5a2be93cd685e6.zip
Added new functions and script name completion in script plugins, fixed some bugs in weelist management and script plugins
New functions in script plugins API: gettext, ngettext, list_new, list_add, list_search, list_casesearch, list_get, list_set, list_next, list_prev, list_string, list_size, list_remove, list_remove_all, list_free.
-rw-r--r--src/core/wee-list.c22
-rw-r--r--src/plugins/scripts/lua/weechat-lua-api.c830
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c27
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c670
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c23
-rw-r--r--src/plugins/scripts/python/weechat-python-api.c743
-rw-r--r--src/plugins/scripts/python/weechat-python.c23
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c813
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c32
-rw-r--r--src/plugins/scripts/script.c57
-rw-r--r--src/plugins/scripts/script.h10
11 files changed, 2660 insertions, 590 deletions
diff --git a/src/core/wee-list.c b/src/core/wee-list.c
index 8f5e23262..70ed465de 100644
--- a/src/core/wee-list.c
+++ b/src/core/wee-list.c
@@ -170,7 +170,7 @@ weelist_search (struct t_weelist *weelist, char *data)
for (ptr_item = weelist->items; ptr_item;
ptr_item = ptr_item->next_item)
{
- if (string_strcasecmp (data, ptr_item->data) == 0)
+ if (strcmp (data, ptr_item->data) == 0)
return ptr_item;
}
/* data not found in list */
@@ -247,7 +247,10 @@ weelist_set (struct t_weelist_item *item, char *new_value)
struct t_weelist_item *
weelist_next (struct t_weelist_item *item)
{
- return item->next_item;
+ if (item)
+ return item->next_item;
+
+ return NULL;
}
/*
@@ -257,7 +260,10 @@ weelist_next (struct t_weelist_item *item)
struct t_weelist_item *
weelist_prev (struct t_weelist_item *item)
{
- return item->prev_item;
+ if (item)
+ return item->prev_item;
+
+ return NULL;
}
/*
@@ -267,7 +273,10 @@ weelist_prev (struct t_weelist_item *item)
char *
weelist_string (struct t_weelist_item *item)
{
- return item->data;
+ if (item)
+ return item->data;
+
+ return NULL;
}
/*
@@ -277,7 +286,10 @@ weelist_string (struct t_weelist_item *item)
int
weelist_size (struct t_weelist *weelist)
{
- return weelist->size;
+ if (weelist)
+ return weelist->size;
+
+ return 0;
}
/*
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c
index a3373c9f0..d593f489b 100644
--- a/src/plugins/scripts/lua/weechat-lua-api.c
+++ b/src/plugins/scripts/lua/weechat-lua-api.c
@@ -20,6 +20,10 @@
#undef _
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
@@ -48,6 +52,9 @@
if (__string) \
free (__string); \
return 1;
+#define LUA_RETURN_INT(__int) \
+ lua_pushnumber (lua_current_interpreter, __int); \
+ return 1;
/*
@@ -97,8 +104,7 @@ weechat_lua_api_register (lua_State *L)
"\"%s\" (another script already "
"exists with this name)"),
weechat_prefix ("error"), "lua", name);
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
+ LUA_RETURN_ERROR;
}
/* register script */
@@ -123,12 +129,10 @@ weechat_lua_api_register (lua_State *L)
}
else
{
- lua_pushnumber (lua_current_interpreter, 0);
- return 1;
+ LUA_RETURN_ERROR;
}
- lua_pushnumber (lua_current_interpreter, 1);
- return 1;
+ LUA_RETURN_OK;
}
/*
@@ -196,7 +200,7 @@ weechat_lua_api_iconv_to_internal (lua_State *L)
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("iconv_to_internal");
- LUA_RETURN_ERROR;
+ LUA_RETURN_EMPTY;
}
charset = lua_tostring (lua_current_interpreter, -2);
@@ -235,7 +239,7 @@ weechat_lua_api_iconv_from_internal (lua_State *L)
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("iconv_from_internal");
- LUA_RETURN_ERROR;
+ LUA_RETURN_EMPTY;
}
charset = lua_tostring (lua_current_interpreter, -2);
@@ -246,6 +250,82 @@ weechat_lua_api_iconv_from_internal (lua_State *L)
}
/*
+ * weechat_lua_api_gettext: get translated string
+ */
+
+static int
+weechat_lua_api_gettext (lua_State *L)
+{
+ const char *string;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("gettext");
+ LUA_RETURN_EMPTY;
+ }
+
+ string = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("gettext");
+ LUA_RETURN_EMPTY;
+ }
+
+ string = lua_tostring (lua_current_interpreter, -1);
+
+ result = weechat_gettext ((char *)string);
+ LUA_RETURN_STRING(result);
+}
+
+/*
+ * weechat_lua_api_ngettext: get translated string with plural form
+ */
+
+static int
+weechat_lua_api_ngettext (lua_State *L)
+{
+ const char *single, *plural;
+ char *result;
+ int n, count;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("ngettext");
+ LUA_RETURN_EMPTY;
+ }
+
+ single = NULL;
+ plural = NULL;
+ count = 0;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("ngettext");
+ LUA_RETURN_EMPTY;
+ }
+
+ single = lua_tostring (lua_current_interpreter, -3);
+ plural = lua_tostring (lua_current_interpreter, -2);
+ count = lua_tonumber (lua_current_interpreter, -1);
+
+ result = weechat_ngettext ((char *)single, (char *)plural, count);
+ LUA_RETURN_STRING(result);
+}
+
+/*
* weechat_lua_api_mkdir_home: create a directory in WeeChat home
*/
@@ -324,6 +404,480 @@ weechat_lua_api_mkdir (lua_State *L)
}
/*
+ * weechat_lua_api_list_new: create a new list
+ */
+
+static int
+weechat_lua_api_list_new (lua_State *L)
+{
+ char *result;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_new");
+ LUA_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_new ());
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_list_add: add a string to list
+ */
+
+static int
+weechat_lua_api_list_add (lua_State *L)
+{
+ const char *weelist, *data, *where;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_add");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ data = NULL;
+ where = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -3);
+ data = lua_tostring (lua_current_interpreter, -2);
+ where = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_list_add (script_str2ptr ((char *)weelist),
+ (char *)data,
+ (char *)where));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_list_search: search a string in list
+ */
+
+static int
+weechat_lua_api_list_search (lua_State *L)
+{
+ const char *weelist, *data;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_search");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ data = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_search");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -2);
+ data = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_list_search (script_str2ptr ((char *)weelist),
+ (char *)data));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_list_casesearch: search a string in list (ignore case)
+ */
+
+static int
+weechat_lua_api_list_casesearch (lua_State *L)
+{
+ const char *weelist, *data;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_casesearch");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ data = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_casesearch");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -2);
+ data = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_list_casesearch (script_str2ptr ((char *)weelist),
+ (char *)data));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_list_get: get item by position
+ */
+
+static int
+weechat_lua_api_list_get (lua_State *L)
+{
+ const char *weelist;
+ char *result;
+ int position, n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_get");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ position = 0;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_get");
+ LUA_RETURN_EMPTY;
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -2);
+ position = lua_tonumber (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_list_get (script_str2ptr ((char *)weelist),
+ position));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_list_set: set new value for item
+ */
+
+static int
+weechat_lua_api_list_set (lua_State *L)
+{
+ const char *item, *new_value;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_set");
+ LUA_RETURN_ERROR;
+ }
+
+ item = NULL;
+ new_value = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_set");
+ LUA_RETURN_ERROR;
+ }
+
+ item = lua_tostring (lua_current_interpreter, -2);
+ new_value = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_list_set (script_str2ptr ((char *)item),
+ (char *)new_value);
+
+ LUA_RETURN_OK;
+}
+
+/*
+ * weechat_lua_api_list_next: get next item
+ */
+
+static int
+weechat_lua_api_list_next (lua_State *L)
+{
+ const char *item;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_next");
+ LUA_RETURN_EMPTY;
+ }
+
+ item = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_next");
+ LUA_RETURN_EMPTY;
+ }
+
+ item = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_list_next (script_str2ptr ((char *)item)));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_list_prev: get previous item
+ */
+
+static int
+weechat_lua_api_list_prev (lua_State *L)
+{
+ const char *item;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_prev");
+ LUA_RETURN_EMPTY;
+ }
+
+ item = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_prev");
+ LUA_RETURN_EMPTY;
+ }
+
+ item = lua_tostring (lua_current_interpreter, -1);
+
+ result = script_ptr2str (weechat_list_prev (script_str2ptr ((char *)item)));
+ LUA_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_lua_api_list_string: get string value of item
+ */
+
+static int
+weechat_lua_api_list_string (lua_State *L)
+{
+ const char *item;
+ char *result;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_string");
+ LUA_RETURN_EMPTY;
+ }
+
+ item = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_string");
+ LUA_RETURN_EMPTY;
+ }
+
+ item = lua_tostring (lua_current_interpreter, -1);
+
+ result = weechat_list_string (script_str2ptr ((char *)item));
+ LUA_RETURN_STRING(result);
+}
+
+/*
+ * weechat_lua_api_list_size: get number of elements in list
+ */
+
+static int
+weechat_lua_api_list_size (lua_State *L)
+{
+ const char *weelist;
+ int n, size;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_size");
+ LUA_RETURN_INT(0);
+ }
+
+ weelist = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_size");
+ LUA_RETURN_INT(0);
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -1);
+
+ size = weechat_list_size (script_str2ptr ((char *)weelist));
+ LUA_RETURN_INT(size);
+}
+
+/*
+ * weechat_lua_api_list_remove: remove item from list
+ */
+
+static int
+weechat_lua_api_list_remove (lua_State *L)
+{
+ const char *weelist, *item;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove");
+ LUA_RETURN_ERROR;
+ }
+
+ weelist = NULL;
+ item = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove");
+ LUA_RETURN_ERROR;
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -2);
+ item = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_list_remove (script_str2ptr ((char *)weelist),
+ script_str2ptr ((char *)item));
+
+ LUA_RETURN_OK;
+}
+
+/*
+ * weechat_lua_api_list_remove_all: remove all items from list
+ */
+
+static int
+weechat_lua_api_list_remove_all (lua_State *L)
+{
+ const char *weelist;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove_all");
+ LUA_RETURN_ERROR;
+ }
+
+ weelist = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove_all");
+ LUA_RETURN_ERROR;
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_list_remove_all (script_str2ptr ((char *)weelist));
+
+ LUA_RETURN_OK;
+}
+
+/*
+ * weechat_lua_api_list_free: free list
+ */
+
+static int
+weechat_lua_api_list_free (lua_State *L)
+{
+ const char *weelist;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_free");
+ LUA_RETURN_ERROR;
+ }
+
+ weelist = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_free");
+ LUA_RETURN_ERROR;
+ }
+
+ weelist = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_list_free (script_str2ptr ((char *)weelist));
+
+ LUA_RETURN_OK;
+}
+
+/*
* weechat_lua_api_prefix: get a prefix, used for display
*/
@@ -350,7 +904,7 @@ weechat_lua_api_prefix (lua_State *L)
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("prefix");
- LUA_RETURN_ERROR;
+ LUA_RETURN_EMPTY;
}
prefix = lua_tostring (lua_current_interpreter, -1);
@@ -386,7 +940,7 @@ weechat_lua_api_color (lua_State *L)
if (n < 1)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("color");
- LUA_RETURN_ERROR;
+ LUA_RETURN_EMPTY;
}
color = lua_tostring (lua_current_interpreter, -1);
@@ -430,7 +984,7 @@ weechat_lua_api_print (lua_State *L)
script_api_printf (weechat_lua_plugin,
lua_current_script,
- script_string_to_pointer ((char *)buffer),
+ script_str2ptr ((char *)buffer),
"%s", (char *)message);
LUA_RETURN_OK;
@@ -566,7 +1120,7 @@ weechat_lua_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- lua_argv[0] = script_pointer_to_string (buffer);
+ lua_argv[0] = script_ptr2str (buffer);
lua_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg;
lua_argv[2] = NULL;
@@ -599,7 +1153,6 @@ weechat_lua_api_hook_command (lua_State *L)
const char *function;
char *result;
int n;
- struct t_hook *new_hook;
/* make C compiler happy */
(void) L;
@@ -632,17 +1185,15 @@ weechat_lua_api_hook_command (lua_State *L)
completion = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_hook = script_api_hook_command (weechat_lua_plugin,
- lua_current_script,
- (char *)command,
- (char *)description,
- (char *)args,
- (char *)args_description,
- (char *)completion,
- &weechat_lua_api_hook_command_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_command (weechat_lua_plugin,
+ lua_current_script,
+ (char *)command,
+ (char *)description,
+ (char *)args,
+ (char *)args_description,
+ (char *)completion,
+ &weechat_lua_api_hook_command_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -685,7 +1236,6 @@ weechat_lua_api_hook_timer (lua_State *L)
int n, interval, align_second, max_calls;
const char *function;
char *result;
- struct t_hook *new_hook;
/* make C compiler happy */
(void) L;
@@ -714,15 +1264,13 @@ weechat_lua_api_hook_timer (lua_State *L)
max_calls = lua_tonumber (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_hook = script_api_hook_timer (weechat_lua_plugin,
- lua_current_script,
- interval,
- align_second,
- max_calls,
- &weechat_lua_api_hook_timer_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_timer (weechat_lua_plugin,
+ lua_current_script,
+ interval,
+ align_second,
+ max_calls,
+ &weechat_lua_api_hook_timer_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -765,7 +1313,6 @@ weechat_lua_api_hook_fd (lua_State *L)
int n, fd, read, write, exception;
const char *function;
char *result;
- struct t_hook *new_hook;
/* make C compiler happy */
(void) L;
@@ -796,16 +1343,14 @@ weechat_lua_api_hook_fd (lua_State *L)
exception = lua_tonumber (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_hook = script_api_hook_fd (weechat_lua_plugin,
- lua_current_script,
- fd,
- read,
- write,
- exception,
- &weechat_lua_api_hook_fd_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_fd (weechat_lua_plugin,
+ lua_current_script,
+ fd,
+ read,
+ write,
+ exception,
+ &weechat_lua_api_hook_fd_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -826,7 +1371,7 @@ weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
- lua_argv[0] = script_pointer_to_string (buffer);
+ lua_argv[0] = script_ptr2str (buffer);
lua_argv[1] = timebuffer;
lua_argv[2] = prefix;
lua_argv[3] = message;
@@ -858,7 +1403,6 @@ weechat_lua_api_hook_print (lua_State *L)
const char *buffer, *message, *function;
char *result;
int n, strip_colors;
- struct t_hook *new_hook;
/* make C compiler happy */
(void) L;
@@ -887,15 +1431,13 @@ weechat_lua_api_hook_print (lua_State *L)
strip_colors = lua_tonumber (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_hook = script_api_hook_print (weechat_lua_plugin,
- lua_current_script,
- script_string_to_pointer ((char *)buffer),
- (char *)message,
- strip_colors,
- &weechat_lua_api_hook_print_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_print (weechat_lua_plugin,
+ lua_current_script,
+ script_str2ptr ((char *)buffer),
+ (char *)message,
+ strip_colors,
+ &weechat_lua_api_hook_print_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -928,7 +1470,7 @@ weechat_lua_api_hook_signal_cb (void *data, char *signal, char *type_data,
}
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
{
- lua_argv[1] = script_pointer_to_string (signal_data);
+ lua_argv[1] = script_ptr2str (signal_data);
free_needed = 1;
}
else
@@ -961,7 +1503,6 @@ weechat_lua_api_hook_signal (lua_State *L)
const char *signal, *function;
char *result;
int n;
- struct t_hook *new_hook;
/* make C compiler happy */
(void) L;
@@ -986,13 +1527,11 @@ weechat_lua_api_hook_signal (lua_State *L)
signal = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_hook = script_api_hook_signal (weechat_lua_plugin,
- lua_current_script,
- (char *)signal,
- &weechat_lua_api_hook_signal_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_signal (weechat_lua_plugin,
+ lua_current_script,
+ (char *)signal,
+ &weechat_lua_api_hook_signal_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -1011,8 +1550,8 @@ weechat_lua_api_hook_signal_send (lua_State *L)
if (!lua_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal");
- LUA_RETURN_EMPTY;
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal_send");
+ LUA_RETURN_ERROR;
}
signal = NULL;
@@ -1023,8 +1562,8 @@ weechat_lua_api_hook_signal_send (lua_State *L)
if (n < 3)
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal");
- LUA_RETURN_EMPTY;
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal_send");
+ LUA_RETURN_ERROR;
}
signal = lua_tostring (lua_current_interpreter, -3);
@@ -1048,7 +1587,7 @@ weechat_lua_api_hook_signal_send (lua_State *L)
{
signal_data = lua_tostring (lua_current_interpreter, -1);
weechat_hook_signal_send ((char *)signal, (char *)type_data,
- script_string_to_pointer ((char *)signal_data));
+ script_str2ptr ((char *)signal_data));
LUA_RETURN_OK;
}
@@ -1100,7 +1639,6 @@ weechat_lua_api_hook_config (lua_State *L)
const char *type, *option, *function;
char *result;
int n;
- struct t_hook *new_hook;
/* make C compiler happy */
(void) L;
@@ -1127,14 +1665,12 @@ weechat_lua_api_hook_config (lua_State *L)
option = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_hook = script_api_hook_config (weechat_lua_plugin,
- lua_current_script,
- (char *)type,
- (char *)option,
- &weechat_lua_api_hook_config_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_config (weechat_lua_plugin,
+ lua_current_script,
+ (char *)type,
+ (char *)option,
+ &weechat_lua_api_hook_config_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -1154,8 +1690,8 @@ weechat_lua_api_hook_completion_cb (void *data, char *completion,
script_callback = (struct t_script_callback *)data;
lua_argv[0] = completion;
- lua_argv[1] = script_pointer_to_string (buffer);
- lua_argv[2] = script_pointer_to_string (list);
+ lua_argv[1] = script_ptr2str (buffer);
+ lua_argv[2] = script_ptr2str (list);
lua_argv[3] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
@@ -1188,7 +1724,6 @@ weechat_lua_api_hook_completion (lua_State *L)
const char *completion, *function;
char *result;
int n;
- struct t_hook *new_hook;
/* make C compiler happy */
(void) L;
@@ -1213,13 +1748,11 @@ weechat_lua_api_hook_completion (lua_State *L)
completion = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_hook = script_api_hook_completion (weechat_lua_plugin,
- lua_current_script,
- (char *)completion,
- &weechat_lua_api_hook_completion_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_completion (weechat_lua_plugin,
+ lua_current_script,
+ (char *)completion,
+ &weechat_lua_api_hook_completion_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -1256,7 +1789,7 @@ weechat_lua_api_unhook (lua_State *L)
if (script_api_unhook (weechat_lua_plugin,
lua_current_script,
- script_string_to_pointer ((char *)hook)))
+ script_str2ptr ((char *)hook)))
LUA_RETURN_OK;
LUA_RETURN_ERROR;
@@ -1298,7 +1831,7 @@ weechat_lua_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- lua_argv[0] = script_pointer_to_string (buffer);
+ lua_argv[0] = script_ptr2str (buffer);
lua_argv[2] = input_data;
lua_argv[3] = NULL;
@@ -1330,7 +1863,6 @@ weechat_lua_api_buffer_new (lua_State *L)
const char *category, *name, *function;
char *result;
int n;
- struct t_gui_buffer *new_buffer;
/* make C compiler happy */
(void) L;
@@ -1357,14 +1889,12 @@ weechat_lua_api_buffer_new (lua_State *L)
name = lua_tostring (lua_current_interpreter, -2);
function = lua_tostring (lua_current_interpreter, -1);
- new_buffer = script_api_buffer_new (weechat_lua_plugin,
- lua_current_script,
- (char *)category,
- (char *)name,
- &weechat_lua_api_input_data_cb,
- (char *)function);
-
- result = script_pointer_to_string (new_buffer);
+ result = script_ptr2str (script_api_buffer_new (weechat_lua_plugin,
+ lua_current_script,
+ (char *)category,
+ (char *)name,
+ &weechat_lua_api_input_data_cb,
+ (char *)function));
LUA_RETURN_STRING_FREE(result);
}
@@ -1378,7 +1908,6 @@ weechat_lua_api_buffer_search (lua_State *L)
const char *category, *name;
char *result;
int n;
- struct t_gui_buffer *ptr_buffer;
/* make C compiler happy */
(void) L;
@@ -1403,10 +1932,8 @@ weechat_lua_api_buffer_search (lua_State *L)
category = lua_tostring (lua_current_interpreter, -2);
name = lua_tostring (lua_current_interpreter, -1);
- ptr_buffer = weechat_buffer_search ((char *)category,
- (char *)name);
-
- result = script_pointer_to_string (ptr_buffer);
+ result = script_ptr2str (weechat_buffer_search ((char *)category,
+ (char *)name));
LUA_RETURN_STRING_FREE(result);
}
@@ -1426,7 +1953,7 @@ weechat_lua_api_buffer_close (lua_State *L)
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_close");
- LUA_RETURN_EMPTY;
+ LUA_RETURN_ERROR;
}
buffer = NULL;
@@ -1437,7 +1964,7 @@ weechat_lua_api_buffer_close (lua_State *L)
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_close");
- LUA_RETURN_EMPTY;
+ LUA_RETURN_ERROR;
}
buffer = lua_tostring (lua_current_interpreter, -2);
@@ -1445,7 +1972,7 @@ weechat_lua_api_buffer_close (lua_State *L)
script_api_buffer_close (weechat_lua_plugin,
lua_current_script,
- script_string_to_pointer ((char *)buffer),
+ script_str2ptr ((char *)buffer),
switch_to_another);
LUA_RETURN_OK;
@@ -1485,7 +2012,7 @@ weechat_lua_api_buffer_get (lua_State *L)
buffer = lua_tostring (lua_current_interpreter, -2);
property = lua_tostring (lua_current_interpreter, -1);
- value = weechat_buffer_get (script_string_to_pointer ((char *)buffer),
+ value = weechat_buffer_get (script_str2ptr ((char *)buffer),
(char *)property);
LUA_RETURN_STRING(value);
}
@@ -1506,7 +2033,7 @@ weechat_lua_api_buffer_set (lua_State *L)
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("buffer_set");
- LUA_RETURN_EMPTY;
+ LUA_RETURN_ERROR;
}
buffer = NULL;
@@ -1517,14 +2044,14 @@ weechat_lua_api_buffer_set (lua_State *L)
if (n < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_set");
- LUA_RETURN_EMPTY;
+ LUA_RETURN_ERROR;
}
buffer = lua_tostring (lua_current_interpreter, -3);
property = lua_tostring (lua_current_interpreter, -2);
value = lua_tostring (lua_current_interpreter, -1);
- weechat_buffer_set (script_string_to_pointer ((char *)buffer),
+ weechat_buffer_set (script_str2ptr ((char *)buffer),
(char *)property,
(char *)value);
@@ -1541,7 +2068,6 @@ weechat_lua_api_nicklist_add_group (lua_State *L)
const char *buffer, *parent_group, *name, *color;
char *result;
int n, visible;
- struct t_gui_nick_group *new_group;
/* make C compiler happy */
(void) L;
@@ -1572,13 +2098,11 @@ weechat_lua_api_nicklist_add_group (lua_State *L)
color = lua_tostring (lua_current_interpreter, -2);
visible = lua_tonumber (lua_current_interpreter, -1);
- new_group = weechat_nicklist_add_group (script_string_to_pointer ((char *)buffer),
- script_string_to_pointer ((char *)parent_group),
- (char *)name,
- (char *)color,
- visible);
-
- result = script_pointer_to_string (new_group);
+ result = script_ptr2str (weechat_nicklist_add_group (script_str2ptr ((char *)buffer),
+ script_str2ptr ((char *)parent_group),
+ (char *)name,
+ (char *)color,
+ visible));
LUA_RETURN_STRING_FREE(result);
}
@@ -1592,7 +2116,6 @@ weechat_lua_api_nicklist_search_group (lua_State *L)
const char *buffer, *from_group, *name;
char *result;
int n;
- struct t_gui_nick_group *ptr_group;
/* make C compiler happy */
(void) L;
@@ -1619,11 +2142,9 @@ weechat_lua_api_nicklist_search_group (lua_State *L)
from_group = lua_tostring (lua_current_interpreter, -2);
name = lua_tostring (lua_current_interpreter, -1);
- ptr_group = weechat_nicklist_search_group (script_string_to_pointer ((char *)buffer),
- script_string_to_pointer ((char *)from_group),
- (char *)name);
-
- result = script_pointer_to_string (ptr_group);
+ result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr ((char *)buffer),
+ script_str2ptr ((char *)from_group),
+ (char *)name));
LUA_RETURN_STRING_FREE(result);
}
@@ -1637,7 +2158,6 @@ weechat_lua_api_nicklist_add_nick (lua_State *L)
const char *buffer, *group, *name, *color, *prefix, *prefix_color;
char char_prefix, *result;
int n, visible;
- struct t_gui_nick *new_nick;
/* make C compiler happy */
(void) L;
@@ -1677,15 +2197,13 @@ weechat_lua_api_nicklist_add_nick (lua_State *L)
else
char_prefix = ' ';
- new_nick = weechat_nicklist_add_nick (script_string_to_pointer ((char *)buffer),
- script_string_to_pointer ((char *)group),
- (char *)name,
- (char *)color,
- char_prefix,
- (char *)prefix_color,
- visible);
-
- result = script_pointer_to_string (new_nick);
+ result = script_ptr2str (weechat_nicklist_add_nick (script_str2ptr ((char *)buffer),
+ script_str2ptr ((char *)group),
+ (char *)name,
+ (char *)color,
+ char_prefix,
+ (char *)prefix_color,
+ visible));
LUA_RETURN_STRING_FREE(result);
}
@@ -1699,7 +2217,6 @@ weechat_lua_api_nicklist_search_nick (lua_State *L)
const char *buffer, *from_group, *name;
char *result;
int n;
- struct t_gui_nick *ptr_nick;
/* make C compiler happy */
(void) L;
@@ -1726,11 +2243,9 @@ weechat_lua_api_nicklist_search_nick (lua_State *L)
from_group = lua_tostring (lua_current_interpreter, -2);
name = lua_tostring (lua_current_interpreter, -1);
- ptr_nick = weechat_nicklist_search_nick (script_string_to_pointer ((char *)buffer),
- script_string_to_pointer ((char *)from_group),
- (char *)name);
-
- result = script_pointer_to_string (ptr_nick);
+ result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr ((char *)buffer),
+ script_str2ptr ((char *)from_group),
+ (char *)name));
LUA_RETURN_STRING_FREE(result);
}
@@ -1767,8 +2282,8 @@ weechat_lua_api_nicklist_remove_group (lua_State *L)
buffer = lua_tostring (lua_current_interpreter, -3);
group = lua_tostring (lua_current_interpreter, -2);
- weechat_nicklist_remove_group (script_string_to_pointer ((char *)buffer),
- script_string_to_pointer ((char *)group));
+ weechat_nicklist_remove_group (script_str2ptr ((char *)buffer),
+ script_str2ptr ((char *)group));
LUA_RETURN_OK;
}
@@ -1806,8 +2321,8 @@ weechat_lua_api_nicklist_remove_nick (lua_State *L)
buffer = lua_tostring (lua_current_interpreter, -3);
nick = lua_tostring (lua_current_interpreter, -2);
- weechat_nicklist_remove_nick (script_string_to_pointer ((char *)buffer),
- script_string_to_pointer ((char *)nick));
+ weechat_nicklist_remove_nick (script_str2ptr ((char *)buffer),
+ script_str2ptr ((char *)nick));
LUA_RETURN_OK;
}
@@ -1843,7 +2358,7 @@ weechat_lua_api_nicklist_remove_all (lua_State *L)
buffer = lua_tostring (lua_current_interpreter, -3);
- weechat_nicklist_remove_all (script_string_to_pointer ((char *)buffer));
+ weechat_nicklist_remove_all (script_str2ptr ((char *)buffer));
LUA_RETURN_OK;
}
@@ -1864,7 +2379,7 @@ weechat_lua_api_command (lua_State *L)
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("command");
- LUA_RETURN_EMPTY;
+ LUA_RETURN_ERROR;
}
command = NULL;
@@ -1874,7 +2389,7 @@ weechat_lua_api_command (lua_State *L)
if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("command");
- LUA_RETURN_EMPTY;
+ LUA_RETURN_ERROR;
}
buffer = lua_tostring (lua_current_interpreter, -2);
@@ -1882,7 +2397,7 @@ weechat_lua_api_command (lua_State *L)
script_api_command (weechat_lua_plugin,
lua_current_script,
- script_string_to_pointer ((char *)buffer),
+ script_str2ptr ((char *)buffer),
(char *)command);
LUA_RETURN_OK;
@@ -2997,8 +3512,23 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "charset_set", &weechat_lua_api_charset_set },
{ "iconv_to_internal", &weechat_lua_api_iconv_to_internal },
{ "iconv_from_internal", &weechat_lua_api_iconv_from_internal },
+ { "gettext", &weechat_lua_api_gettext },
+ { "ngettext", &weechat_lua_api_ngettext },
{ "mkdir_home", &weechat_lua_api_mkdir_home },
{ "mkdir", &weechat_lua_api_mkdir },
+ { "list_new", &weechat_lua_api_list_new },
+ { "list_add", &weechat_lua_api_list_add },
+ { "list_search", &weechat_lua_api_list_search },
+ { "list_casesearch", &weechat_lua_api_list_casesearch },
+ { "list_get", &weechat_lua_api_list_get },
+ { "list_set", &weechat_lua_api_list_set },
+ { "list_next", &weechat_lua_api_list_next },
+ { "list_prev", &weechat_lua_api_list_prev },
+ { "list_string", &weechat_lua_api_list_string },
+ { "list_size", &weechat_lua_api_list_size },
+ { "list_remove", &weechat_lua_api_list_remove },
+ { "list_remove_all", &weechat_lua_api_list_remove_all },
+ { "list_free", &weechat_lua_api_list_free },
{ "prefix", &weechat_lua_api_prefix },
{ "color", &weechat_lua_api_color },
{ "print", &weechat_lua_api_print },
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index d06923369..90a4c92c8 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -20,6 +20,10 @@
#undef _
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
@@ -397,6 +401,25 @@ weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
}
/*
+ * weechat_lua_completion_cb: callback for script completion
+ */
+
+int
+weechat_lua_completion_cb (void *data, char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) completion;
+ (void) buffer;
+
+ script_completion (weechat_lua_plugin, list, lua_scripts);
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* weechat_lua_dump_data_cb: dump Lua plugin data in WeeChat log file
*/
@@ -426,7 +449,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
weechat_lua_plugin = plugin;
script_init (weechat_lua_plugin,
- &weechat_lua_command_cb, &weechat_lua_dump_data_cb,
+ &weechat_lua_command_cb,
+ &weechat_lua_completion_cb,
+ &weechat_lua_dump_data_cb,
&weechat_lua_load_cb);
/* init ok */
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index 27c50e5a7..6a7d5d755 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -55,6 +55,10 @@
} \
XST_mPV (0, ""); \
XSRETURN (1)
+#define PERL_RETURN_INT(__int) \
+ XST_mIV (0, __int); \
+ XSRETURN (1);
+
extern void boot_DynaLoader (pTHX_ CV* cv);
@@ -212,6 +216,64 @@ static XS (XS_weechat_iconv_from_internal)
}
/*
+ * weechat::gettext: get translated string
+ */
+
+static XS (XS_weechat_gettext)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("gettext");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("gettext");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = weechat_gettext (SvPV (ST (0), PL_na)); /* string */
+ PERL_RETURN_STRING(result);
+}
+
+/*
+ * weechat::ngettext: get translated string with plural form
+ */
+
+static XS (XS_weechat_ngettext)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("ngettext");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("ngettext");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = weechat_ngettext (SvPV (ST (0), PL_na), /* single */
+ SvPV (ST (1), PL_na), /* plural */
+ SvIV (ST (2))); /* count */
+ PERL_RETURN_STRING(result);
+}
+
+/*
* weechat::mkdir_home: create a directory in WeeChat home
*/
@@ -272,6 +334,372 @@ static XS (XS_weechat_mkdir)
}
/*
+ * weechat::list_new: create a new list
+ */
+
+static XS (XS_weechat_list_new)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) items;
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_new");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_new ());
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::list_add: add a string to list
+ */
+
+static XS (XS_weechat_list_add)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_add");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 3)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_add (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */
+ SvPV (ST (1), PL_na), /* data */
+ SvPV (ST (2), PL_na))); /* where */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::list_search: search a string in list
+ */
+
+static XS (XS_weechat_list_search)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_search");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_search");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_search (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */
+ SvPV (ST (1), PL_na))); /* data */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::list_casesearch: search a string in list (ignore case)
+ */
+
+static XS (XS_weechat_list_casesearch)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_casesearch");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_casesearch");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_casesearch (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */
+ SvPV (ST (1), PL_na))); /* data */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::list_get: get item by position
+ */
+
+static XS (XS_weechat_list_get)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_get");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_get");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_get (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */
+ SvIV (ST (1)))); /* position */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::list_set: set new value for item
+ */
+
+static XS (XS_weechat_list_set)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_set");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_set");
+ PERL_RETURN_ERROR;
+ }
+
+ weechat_list_set (script_str2ptr (SvPV (ST (0), PL_na)), /* item */
+ SvPV (ST (1), PL_na)); /* new_value */
+
+ PERL_RETURN_OK;
+}
+
+/*
+ * weechat::list_next: get next item
+ */
+
+static XS (XS_weechat_list_next)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_next");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_next");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_next (script_str2ptr (SvPV (ST (0), PL_na)))); /* item */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::list_prev: get previous item
+ */
+
+static XS (XS_weechat_list_prev)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_prev");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_prev");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_prev (script_str2ptr (SvPV (ST (0), PL_na)))); /* item */
+ PERL_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat::list_string: get string value of item
+ */
+
+static XS (XS_weechat_list_string)
+{
+ char *result;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_string");
+ PERL_RETURN_EMPTY;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_string");
+ PERL_RETURN_EMPTY;
+ }
+
+ result = weechat_list_string (script_str2ptr (SvPV (ST (0), PL_na))); /* item */
+ PERL_RETURN_STRING(result);
+}
+
+/*
+ * weechat::list_size: get number of elements in list
+ */
+
+static XS (XS_weechat_list_size)
+{
+ int size;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_size");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_size");
+ PERL_RETURN_INT(0);
+ }
+
+ size = weechat_list_size (script_str2ptr (SvPV (ST (0), PL_na))); /* weelist */
+ PERL_RETURN_INT(size);
+}
+
+/*
+ * weechat::list_remove: remove item from list
+ */
+
+static XS (XS_weechat_list_remove)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove");
+ PERL_RETURN_ERROR;
+ }
+
+ weechat_list_remove (script_str2ptr (SvPV (ST (0), PL_na)), /* weelist */
+ script_str2ptr (SvPV (ST (1), PL_na))); /* item */
+
+ PERL_RETURN_OK;
+}
+
+/*
+ * weechat::list_remove_all: remove all items from list
+ */
+
+static XS (XS_weechat_list_remove_all)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove_all");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove_all");
+ PERL_RETURN_ERROR;
+ }
+
+ weechat_list_remove_all (script_str2ptr (SvPV (ST (0), PL_na))); /* weelist */
+
+ PERL_RETURN_OK;
+}
+
+/*
+ * weechat::list_free: free list
+ */
+
+static XS (XS_weechat_list_free)
+{
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_free");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 1)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_free");
+ PERL_RETURN_ERROR;
+ }
+
+ weechat_list_free (script_str2ptr (SvPV (ST (0), PL_na))); /* weelist */
+
+ PERL_RETURN_OK;
+}
+
+/*
* weechat::prefix: get a prefix, used for display
*/
@@ -352,7 +780,7 @@ static XS (XS_weechat_print)
script_api_printf (weechat_perl_plugin,
perl_current_script,
- script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
"%s", SvPV (ST (1), PL_na)); /* message */
PERL_RETURN_OK;
@@ -460,7 +888,7 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- perl_argv[0] = script_pointer_to_string (buffer);
+ perl_argv[0] = script_ptr2str (buffer);
perl_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg;
perl_argv[2] = NULL;
@@ -488,7 +916,6 @@ weechat_perl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
static XS (XS_weechat_hook_command)
{
- struct t_hook *new_hook;
char *result;
dXSARGS;
@@ -507,18 +934,16 @@ static XS (XS_weechat_hook_command)
PERL_RETURN_EMPTY;
}
- new_hook = script_api_hook_command (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* command */
- SvPV (ST (1), PL_na), /* description */
- SvPV (ST (2), PL_na), /* args */
- SvPV (ST (3), PL_na), /* args_description */
- SvPV (ST (4), PL_na), /* completion */
- &weechat_perl_api_hook_command_cb,
- SvPV (ST (5), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_hook);
- PERL_RETURN_STRING_FREE(result);;
+ result = script_ptr2str (script_api_hook_command (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* command */
+ SvPV (ST (1), PL_na), /* description */
+ SvPV (ST (2), PL_na), /* args */
+ SvPV (ST (3), PL_na), /* args_description */
+ SvPV (ST (4), PL_na), /* completion */
+ &weechat_perl_api_hook_command_cb,
+ SvPV (ST (5), PL_na))); /* perl function */
+ PERL_RETURN_STRING_FREE(result);
}
/*
@@ -556,7 +981,6 @@ weechat_perl_api_hook_timer_cb (void *data)
static XS (XS_weechat_hook_timer)
{
- struct t_hook *new_hook;
char *result;
dXSARGS;
@@ -575,15 +999,13 @@ static XS (XS_weechat_hook_timer)
PERL_RETURN_EMPTY;
}
- new_hook = script_api_hook_timer (weechat_perl_plugin,
- perl_current_script,
- SvIV (ST (0)), /* interval */
- SvIV (ST (1)), /* align_second */
- SvIV (ST (2)), /* max_calls */
- &weechat_perl_api_hook_timer_cb,
- SvPV (ST (3), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_timer (weechat_perl_plugin,
+ perl_current_script,
+ SvIV (ST (0)), /* interval */
+ SvIV (ST (1)), /* align_second */
+ SvIV (ST (2)), /* max_calls */
+ &weechat_perl_api_hook_timer_cb,
+ SvPV (ST (3), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
@@ -622,7 +1044,6 @@ weechat_perl_api_hook_fd_cb (void *data)
static XS (XS_weechat_hook_fd)
{
- struct t_hook *new_hook;
char *result;
dXSARGS;
@@ -641,16 +1062,14 @@ static XS (XS_weechat_hook_fd)
PERL_RETURN_EMPTY;
}
- new_hook = script_api_hook_fd (weechat_perl_plugin,
- perl_current_script,
- SvIV (ST (0)), /* fd */
- SvIV (ST (1)), /* read */
- SvIV (ST (2)), /* write */
- SvIV (ST (3)), /* exception */
- &weechat_perl_api_hook_fd_cb,
- SvPV (ST (4), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_fd (weechat_perl_plugin,
+ perl_current_script,
+ SvIV (ST (0)), /* fd */
+ SvIV (ST (1)), /* read */
+ SvIV (ST (2)), /* write */
+ SvIV (ST (3)), /* exception */
+ &weechat_perl_api_hook_fd_cb,
+ SvPV (ST (4), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
@@ -671,7 +1090,7 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
- perl_argv[0] = script_pointer_to_string (buffer);
+ perl_argv[0] = script_ptr2str (buffer);
perl_argv[1] = timebuffer;
perl_argv[2] = prefix;
perl_argv[3] = message;
@@ -701,7 +1120,6 @@ weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
static XS (XS_weechat_hook_print)
{
- struct t_hook *new_hook;
char *result;
dXSARGS;
@@ -720,15 +1138,13 @@ static XS (XS_weechat_hook_print)
PERL_RETURN_EMPTY;
}
- new_hook = script_api_hook_print (weechat_perl_plugin,
- perl_current_script,
- script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- SvPV (ST (1), PL_na), /* message */
- SvIV (ST (2)), /* strip_colors */
- &weechat_perl_api_hook_print_cb,
- SvPV (ST (3), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_print (weechat_perl_plugin,
+ perl_current_script,
+ script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
+ SvPV (ST (1), PL_na), /* message */
+ SvIV (ST (2)), /* strip_colors */
+ &weechat_perl_api_hook_print_cb,
+ SvPV (ST (3), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
@@ -761,7 +1177,7 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data,
}
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
{
- perl_argv[1] = script_pointer_to_string (signal_data);
+ perl_argv[1] = script_ptr2str (signal_data);
free_needed = 1;
}
else
@@ -792,7 +1208,6 @@ weechat_perl_api_hook_signal_cb (void *data, char *signal, char *type_data,
static XS (XS_weechat_hook_signal)
{
- struct t_hook *new_hook;
char *result;
dXSARGS;
@@ -802,22 +1217,20 @@ static XS (XS_weechat_hook_signal)
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal");
- PERL_RETURN_ERROR;
+ PERL_RETURN_EMPTY;
}
if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal");
- PERL_RETURN_ERROR;
+ PERL_RETURN_EMPTY;
}
- new_hook = script_api_hook_signal (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* signal */
- &weechat_perl_api_hook_signal_cb,
- SvPV (ST (1), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_signal (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* signal */
+ &weechat_perl_api_hook_signal_cb,
+ SvPV (ST (1), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
@@ -866,7 +1279,7 @@ static XS (XS_weechat_hook_signal_send)
{
weechat_hook_signal_send (SvPV (ST (0), PL_na), /* signal */
type_data,
- script_string_to_pointer (SvPV (ST (2), PL_na))); /* signal_data */
+ script_str2ptr (SvPV (ST (2), PL_na))); /* signal_data */
PERL_RETURN_OK;
}
@@ -914,7 +1327,6 @@ weechat_perl_api_hook_config_cb (void *data, char *type, char *option,
static XS (XS_weechat_hook_config)
{
- struct t_hook *new_hook;
char *result;
dXSARGS;
@@ -933,14 +1345,12 @@ static XS (XS_weechat_hook_config)
PERL_RETURN_EMPTY;
}
- new_hook = script_api_hook_config (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* type */
- SvPV (ST (1), PL_na), /* option */
- &weechat_perl_api_hook_config_cb,
- SvPV (ST (2), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_config (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* type */
+ SvPV (ST (1), PL_na), /* option */
+ &weechat_perl_api_hook_config_cb,
+ SvPV (ST (2), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
@@ -960,8 +1370,8 @@ weechat_perl_api_hook_completion_cb (void *data, char *completion,
script_callback = (struct t_script_callback *)data;
perl_argv[0] = completion;
- perl_argv[1] = script_pointer_to_string (buffer);
- perl_argv[2] = script_pointer_to_string (list);
+ perl_argv[1] = script_ptr2str (buffer);
+ perl_argv[2] = script_ptr2str (list);
perl_argv[3] = NULL;
rc = (int *) weechat_perl_exec (script_callback->script,
@@ -990,7 +1400,6 @@ weechat_perl_api_hook_completion_cb (void *data, char *completion,
static XS (XS_weechat_hook_completion)
{
- struct t_hook *new_hook;
char *result;
dXSARGS;
@@ -1009,13 +1418,11 @@ static XS (XS_weechat_hook_completion)
PERL_RETURN_EMPTY;
}
- new_hook = script_api_hook_completion (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* completion */
- &weechat_perl_api_hook_completion_cb,
- SvPV (ST (1), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_completion (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* completion */
+ &weechat_perl_api_hook_completion_cb,
+ SvPV (ST (1), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
@@ -1044,7 +1451,7 @@ static XS (XS_weechat_unhook)
if (script_api_unhook (weechat_perl_plugin,
perl_current_script,
- script_string_to_pointer (SvPV (ST (0), PL_na))))
+ script_str2ptr (SvPV (ST (0), PL_na))))
PERL_RETURN_OK;
PERL_RETURN_ERROR;
@@ -1088,7 +1495,7 @@ weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- perl_argv[0] = script_pointer_to_string (buffer);
+ perl_argv[0] = script_ptr2str (buffer);
perl_argv[1] = input_data;
perl_argv[2] = NULL;
@@ -1115,7 +1522,6 @@ weechat_perl_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
static XS (XS_weechat_buffer_new)
{
- struct t_gui_buffer *new_buffer;
char *result;
dXSARGS;
@@ -1134,14 +1540,12 @@ static XS (XS_weechat_buffer_new)
PERL_RETURN_EMPTY;
}
- new_buffer = script_api_buffer_new (weechat_perl_plugin,
- perl_current_script,
- SvPV (ST (0), PL_na), /* category */
- SvPV (ST (1), PL_na), /* name */
- &weechat_perl_api_input_data_cb,
- SvPV (ST (2), PL_na)); /* perl function */
-
- result = script_pointer_to_string (new_buffer);
+ result = script_ptr2str (script_api_buffer_new (weechat_perl_plugin,
+ perl_current_script,
+ SvPV (ST (0), PL_na), /* category */
+ SvPV (ST (1), PL_na), /* name */
+ &weechat_perl_api_input_data_cb,
+ SvPV (ST (2), PL_na))); /* perl function */
PERL_RETURN_STRING_FREE(result);
}
@@ -1151,7 +1555,6 @@ static XS (XS_weechat_buffer_new)
static XS (XS_weechat_buffer_search)
{
- struct t_gui_buffer *ptr_buffer;
char *result;
dXSARGS;
@@ -1170,10 +1573,8 @@ static XS (XS_weechat_buffer_search)
PERL_RETURN_EMPTY;
}
- ptr_buffer = weechat_buffer_search (SvPV (ST (0), PL_na), /* category */
- SvPV (ST (1), PL_na)); /* name */
-
- result = script_pointer_to_string (ptr_buffer);
+ result = script_ptr2str (weechat_buffer_search (SvPV (ST (0), PL_na), /* category */
+ SvPV (ST (1), PL_na))); /* name */
PERL_RETURN_STRING_FREE(result);
}
@@ -1202,7 +1603,7 @@ static XS (XS_weechat_buffer_close)
script_api_buffer_close (weechat_perl_plugin,
perl_current_script,
- script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
SvIV (ST (1))); /* switch_to_another */
PERL_RETURN_OK;
@@ -1232,7 +1633,7 @@ static XS (XS_weechat_buffer_get)
PERL_RETURN_EMPTY;
}
- value = weechat_buffer_get (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ value = weechat_buffer_get (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
SvPV (ST (1), PL_na)); /* property */
PERL_RETURN_STRING(value);
}
@@ -1260,7 +1661,7 @@ static XS (XS_weechat_buffer_set)
PERL_RETURN_ERROR;
}
- weechat_buffer_set (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ weechat_buffer_set (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
SvPV (ST (1), PL_na), /* property */
SvPV (ST (2), PL_na)); /* value */
@@ -1273,7 +1674,6 @@ static XS (XS_weechat_buffer_set)
static XS (XS_weechat_nicklist_add_group)
{
- struct t_gui_nick_group *new_group;
char *result;
dXSARGS;
@@ -1292,13 +1692,11 @@ static XS (XS_weechat_nicklist_add_group)
PERL_RETURN_EMPTY;
}
- new_group = weechat_nicklist_add_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- script_string_to_pointer (SvPV (ST (1), PL_na)), /* parent_group */
- SvPV (ST (2), PL_na), /* name */
- SvPV (ST (3), PL_na), /* color */
- SvIV (ST (4))); /* visible */
-
- result = script_pointer_to_string (new_group);
+ result = script_ptr2str (weechat_nicklist_add_group (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (1), PL_na)), /* parent_group */
+ SvPV (ST (2), PL_na), /* name */
+ SvPV (ST (3), PL_na), /* color */
+ SvIV (ST (4)))); /* visible */
PERL_RETURN_STRING_FREE(result);
}
@@ -1308,7 +1706,6 @@ static XS (XS_weechat_nicklist_add_group)
static XS (XS_weechat_nicklist_search_group)
{
- struct t_gui_nick_group *ptr_group;
char *result;
dXSARGS;
@@ -1327,11 +1724,9 @@ static XS (XS_weechat_nicklist_search_group)
PERL_RETURN_EMPTY;
}
- ptr_group = weechat_nicklist_search_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- script_string_to_pointer (SvPV (ST (1), PL_na)), /* from_group */
- SvPV (ST (2), PL_na)); /* name */
-
- result = script_pointer_to_string (ptr_group);
+ result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (1), PL_na)), /* from_group */
+ SvPV (ST (2), PL_na))); /* name */
PERL_RETURN_STRING_FREE(result);
}
@@ -1341,7 +1736,6 @@ static XS (XS_weechat_nicklist_search_group)
static XS (XS_weechat_nicklist_add_nick)
{
- struct t_gui_nick *new_nick;
char *prefix, char_prefix, *result;
dXSARGS;
@@ -1366,15 +1760,13 @@ static XS (XS_weechat_nicklist_add_nick)
else
char_prefix = ' ';
- new_nick = weechat_nicklist_add_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- script_string_to_pointer (SvPV (ST (1), PL_na)), /* group */
- SvPV (ST (2), PL_na), /* name */
- SvPV (ST (3), PL_na), /* color */
- char_prefix,
- SvPV (ST (5), PL_na), /* prefix_color */
- SvIV (ST (6))); /* visible */
-
- result = script_pointer_to_string (new_nick);
+ result = script_ptr2str (weechat_nicklist_add_nick (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (1), PL_na)), /* group */
+ SvPV (ST (2), PL_na), /* name */
+ SvPV (ST (3), PL_na), /* color */
+ char_prefix,
+ SvPV (ST (5), PL_na), /* prefix_color */
+ SvIV (ST (6)))); /* visible */
PERL_RETURN_STRING_FREE(result);
}
@@ -1384,7 +1776,6 @@ static XS (XS_weechat_nicklist_add_nick)
static XS (XS_weechat_nicklist_search_nick)
{
- struct t_gui_nick *ptr_nick;
char *result;
dXSARGS;
@@ -1403,11 +1794,9 @@ static XS (XS_weechat_nicklist_search_nick)
PERL_RETURN_EMPTY;
}
- ptr_nick = weechat_nicklist_search_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- script_string_to_pointer (SvPV (ST (1), PL_na)), /* from_group */
- SvPV (ST (2), PL_na)); /* name */
-
- result = script_pointer_to_string (ptr_nick);
+ result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (1), PL_na)), /* from_group */
+ SvPV (ST (2), PL_na))); /* name */
PERL_RETURN_STRING_FREE(result);
}
@@ -1434,8 +1823,8 @@ static XS (XS_weechat_nicklist_remove_group)
PERL_RETURN_ERROR;
}
- weechat_nicklist_remove_group (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- script_string_to_pointer (SvPV (ST (1), PL_na))); /* group */
+ weechat_nicklist_remove_group (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (1), PL_na))); /* group */
PERL_RETURN_OK;
}
@@ -1463,8 +1852,8 @@ static XS (XS_weechat_nicklist_remove_nick)
PERL_RETURN_ERROR;
}
- weechat_nicklist_remove_nick (script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
- script_string_to_pointer (SvPV (ST (1), PL_na))); /* nick */
+ weechat_nicklist_remove_nick (script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (1), PL_na))); /* nick */
PERL_RETURN_OK;
}
@@ -1492,7 +1881,7 @@ static XS (XS_weechat_nicklist_remove_all)
PERL_RETURN_ERROR;
}
- weechat_nicklist_remove_all (script_string_to_pointer (SvPV (ST (0), PL_na))); /* buffer */
+ weechat_nicklist_remove_all (script_str2ptr (SvPV (ST (0), PL_na))); /* buffer */
PERL_RETURN_OK;
}
@@ -1522,7 +1911,7 @@ static XS (XS_weechat_command)
script_api_command (weechat_perl_plugin,
perl_current_script,
- script_string_to_pointer (SvPV (ST (0), PL_na)), /* buffer */
+ script_str2ptr (SvPV (ST (0), PL_na)), /* buffer */
SvPV (ST (1), PL_na)); /* command */
PERL_RETURN_OK;
@@ -2307,8 +2696,23 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::charset_set", XS_weechat_charset_set, "weechat");
newXS ("weechat::iconv_to_internal", XS_weechat_iconv_to_internal, "weechat");
newXS ("weechat::iconv_from_internal", XS_weechat_iconv_from_internal, "weechat");
+ newXS ("weechat::gettext", XS_weechat_gettext, "weechat");
+ newXS ("weechat::ngettext", XS_weechat_ngettext, "weechat");
newXS ("weechat::mkdir_home", XS_weechat_mkdir_home, "weechat");
newXS ("weechat::mkdir", XS_weechat_mkdir, "weechat");
+ newXS ("weechat::list_new", XS_weechat_list_new, "weechat");
+ newXS ("weechat::list_add", XS_weechat_list_add, "weechat");
+ newXS ("weechat::list_search", XS_weechat_list_search, "weechat");
+ newXS ("weechat::list_casesearch", XS_weechat_list_casesearch, "weechat");
+ newXS ("weechat::list_get", XS_weechat_list_get, "weechat");
+ newXS ("weechat::list_set", XS_weechat_list_set, "weechat");
+ newXS ("weechat::list_next", XS_weechat_list_next, "weechat");
+ newXS ("weechat::list_prev", XS_weechat_list_prev, "weechat");
+ newXS ("weechat::list_string", XS_weechat_list_string, "weechat");
+ newXS ("weechat::list_size", XS_weechat_list_size, "weechat");
+ newXS ("weechat::list_remove", XS_weechat_list_remove, "weechat");
+ newXS ("weechat::list_remove_all", XS_weechat_list_remove_all, "weechat");
+ newXS ("weechat::list_free", XS_weechat_list_free, "weechat");
newXS ("weechat::prefix", XS_weechat_prefix, "weechat");
newXS ("weechat::color", XS_weechat_color, "weechat");
newXS ("weechat::print", XS_weechat_print, "weechat");
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index 1486d93bb..19cfa95eb 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -538,6 +538,25 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
}
/*
+ * weechat_perl_completion_cb: callback for script completion
+ */
+
+int
+weechat_perl_completion_cb (void *data, char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) completion;
+ (void) buffer;
+
+ script_completion (weechat_perl_plugin, list, perl_scripts);
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* weechat_perl_dump_data_cb: dump Perl plugin data in WeeChat log file
*/
@@ -584,7 +603,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
#endif
script_init (weechat_perl_plugin,
- &weechat_perl_command_cb, &weechat_perl_dump_data_cb,
+ &weechat_perl_command_cb,
+ &weechat_perl_completion_cb,
+ &weechat_perl_dump_data_cb,
&weechat_perl_load_cb);
/* init ok */
diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c
index 8a7ac6bf3..d9b27bb86 100644
--- a/src/plugins/scripts/python/weechat-python-api.c
+++ b/src/plugins/scripts/python/weechat-python-api.c
@@ -50,6 +50,8 @@
return object; \
} \
return Py_BuildValue ("s", "")
+#define PYTHON_RETURN_INT(__int) \
+ return Py_BuildValue("i", __int);
/*
@@ -214,6 +216,69 @@ weechat_python_api_iconv_from_internal (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_gettext: get translated string
+ */
+
+static PyObject *
+weechat_python_api_gettext (PyObject *self, PyObject *args)
+{
+ char *string, *result;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("gettext");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ string = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &string))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("gettext");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = weechat_gettext (string);
+ PYTHON_RETURN_STRING(result);
+}
+
+/*
+ * weechat_python_api_ngettext: get translated string with plural form
+ */
+
+static PyObject *
+weechat_python_api_ngettext (PyObject *self, PyObject *args)
+{
+ char *single, *plural, *result;
+ int count;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("ngettext");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ single = NULL;
+ plural = NULL;
+ count = 0;
+
+ if (!PyArg_ParseTuple (args, "ssi", &single, &plural, &count))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("ngettext");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = weechat_ngettext (single, plural, count);
+ PYTHON_RETURN_STRING(result);
+}
+
+/*
* weechat_python_api_mkdir_home: create a directory in WeeChat home
*/
@@ -282,6 +347,416 @@ weechat_python_api_mkdir (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_list_new: create a new list
+ */
+
+static PyObject *
+weechat_python_api_list_new (PyObject *self, PyObject *args)
+{
+ char *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+ (void) args;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_new");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_new ());
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_list_add: add a string to list
+ */
+
+static PyObject *
+weechat_python_api_list_add (PyObject *self, PyObject *args)
+{
+ char *weelist, *data, *where, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_add");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ data = NULL;
+ where = NULL;
+
+ if (!PyArg_ParseTuple (args, "sss", &weelist, &data, &where))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_add (script_str2ptr (weelist),
+ data,
+ where));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_list_search: search a string in list
+ */
+
+static PyObject *
+weechat_python_api_list_search (PyObject *self, PyObject *args)
+{
+ char *weelist, *data, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_search");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ data = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &weelist, &data))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_search");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_search (script_str2ptr (weelist),
+ data));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_list_casesearch: search a string in list (ignore case)
+ */
+
+static PyObject *
+weechat_python_api_list_casesearch (PyObject *self, PyObject *args)
+{
+ char *weelist, *data, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_casesearch");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ data = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &weelist, &data))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_casesearch");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_casesearch (script_str2ptr (weelist),
+ data));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_list_get: get item by position
+ */
+
+static PyObject *
+weechat_python_api_list_get (PyObject *self, PyObject *args)
+{
+ char *weelist, *result;
+ int position;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_get");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ weelist = NULL;
+ position = 0;
+
+ if (!PyArg_ParseTuple (args, "si", &weelist, &position))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_get");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_get (script_str2ptr (weelist),
+ position));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_list_set: set new value for item
+ */
+
+static PyObject *
+weechat_python_api_list_set (PyObject *self, PyObject *args)
+{
+ char *item, *new_value;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_set");
+ PYTHON_RETURN_ERROR;
+ }
+
+ item = NULL;
+ new_value = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &item, &new_value))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_set");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weechat_list_set (script_str2ptr (item),
+ new_value);
+
+ PYTHON_RETURN_OK;
+}
+
+/*
+ * weechat_python_api_list_next: get next item
+ */
+
+static PyObject *
+weechat_python_api_list_next (PyObject *self, PyObject *args)
+{
+ char *item, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_next");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ item = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_next");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_next (script_str2ptr (item)));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_list_prev: get previous item
+ */
+
+static PyObject *
+weechat_python_api_list_prev (PyObject *self, PyObject *args)
+{
+ char *item, *result;
+ PyObject *object;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_prev");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ item = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_prev");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_prev (script_str2ptr (item)));
+ PYTHON_RETURN_STRING_FREE(result);
+}
+
+/*
+ * weechat_python_api_list_string: get string value of item
+ */
+
+static PyObject *
+weechat_python_api_list_string (PyObject *self, PyObject *args)
+{
+ char *item, *result;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_string");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ item = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_string");
+ PYTHON_RETURN_EMPTY;
+ }
+
+ result = weechat_list_string (script_str2ptr (item));
+ PYTHON_RETURN_STRING(result);
+}
+
+/*
+ * weechat_python_api_list_size: get number of elements in list
+ */
+
+static PyObject *
+weechat_python_api_list_size (PyObject *self, PyObject *args)
+{
+ char *weelist;
+ int size;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_size");
+ PYTHON_RETURN_INT(0);
+ }
+
+ weelist = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &weelist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_size");
+ PYTHON_RETURN_INT(0);
+ }
+
+ size = weechat_list_size (script_str2ptr (weelist));
+ PYTHON_RETURN_INT(size);
+}
+
+/*
+ * weechat_python_api_list_remove: remove item from list
+ */
+
+static PyObject *
+weechat_python_api_list_remove (PyObject *self, PyObject *args)
+{
+ char *weelist, *item;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weelist = NULL;
+ item = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &weelist, &item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weechat_list_remove (script_str2ptr (weelist),
+ script_str2ptr (item));
+
+ PYTHON_RETURN_OK;
+}
+
+/*
+ * weechat_python_api_list_remove_all: remove all items from list
+ */
+
+static PyObject *
+weechat_python_api_list_remove_all (PyObject *self, PyObject *args)
+{
+ char *weelist;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove_all");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weelist = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &weelist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove_all");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weechat_list_remove_all (script_str2ptr (weelist));
+
+ PYTHON_RETURN_OK;
+}
+
+/*
+ * weechat_python_api_list_free: free list
+ */
+
+static PyObject *
+weechat_python_api_list_free (PyObject *self, PyObject *args)
+{
+ char *weelist;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_free");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weelist = NULL;
+
+ if (!PyArg_ParseTuple (args, "s", &weelist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_free");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weechat_list_free (script_str2ptr (weelist));
+
+ PYTHON_RETURN_OK;
+}
+
+/*
* weechat_python_api_prefix: get a prefix, used for display
*/
@@ -337,7 +812,7 @@ weechat_python_api_color (PyObject *self, PyObject *args)
PYTHON_RETURN_EMPTY;
}
- result = weechat_prefix (color);
+ result = weechat_color (color);
PYTHON_RETURN_STRING(result);
}
@@ -370,7 +845,7 @@ weechat_python_api_prnt (PyObject *self, PyObject *args)
script_api_printf (weechat_python_plugin,
python_current_script,
- script_string_to_pointer (buffer),
+ script_str2ptr (buffer),
"%s", message);
PYTHON_RETURN_OK;
@@ -425,7 +900,7 @@ weechat_python_api_infobar_remove (PyObject *self, PyObject *args)
if (!python_current_script)
{
- WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_print");
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("infobar_remove");
PYTHON_RETURN_ERROR;
}
@@ -433,7 +908,7 @@ weechat_python_api_infobar_remove (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "|i", &how_many))
{
- WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_print");
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infobar_remove");
PYTHON_RETURN_ERROR;
}
@@ -492,7 +967,7 @@ weechat_python_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- python_argv[0] = script_pointer_to_string (buffer);
+ python_argv[0] = script_ptr2str (buffer);
python_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg;
python_argv[2] = NULL;
@@ -523,7 +998,6 @@ weechat_python_api_hook_command (PyObject *self, PyObject *args)
{
char *command, *description, *arguments, *args_description, *completion;
char *function, *result;
- struct t_hook *new_hook;
PyObject *object;
/* make C compiler happy */
@@ -546,20 +1020,18 @@ weechat_python_api_hook_command (PyObject *self, PyObject *args)
&args_description, &completion, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_command");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- new_hook = script_api_hook_command (weechat_python_plugin,
- python_current_script,
- command,
- description,
- arguments,
- args_description,
- completion,
- &weechat_python_api_hook_command_cb,
- function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_command (weechat_python_plugin,
+ python_current_script,
+ command,
+ description,
+ arguments,
+ args_description,
+ completion,
+ &weechat_python_api_hook_command_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -601,7 +1073,6 @@ weechat_python_api_hook_timer (PyObject *self, PyObject *args)
{
int interval, align_second, max_calls;
char *function, *result;
- struct t_hook *new_hook;
PyObject *object;
/* make C compiler happy */
@@ -610,7 +1081,7 @@ weechat_python_api_hook_timer (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_timer");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
interval = 10;
@@ -622,18 +1093,16 @@ weechat_python_api_hook_timer (PyObject *self, PyObject *args)
&function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_timer");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- new_hook = script_api_hook_timer (weechat_python_plugin,
- python_current_script,
- interval,
- align_second,
- max_calls,
- &weechat_python_api_hook_timer_cb,
- function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_timer (weechat_python_plugin,
+ python_current_script,
+ interval,
+ align_second,
+ max_calls,
+ &weechat_python_api_hook_timer_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -675,7 +1144,6 @@ weechat_python_api_hook_fd (PyObject *self, PyObject *args)
{
int fd, read, write, exception;
char *function, *result;
- struct t_hook *new_hook;
PyObject *object;
/* make C compiler happy */
@@ -684,7 +1152,7 @@ weechat_python_api_hook_fd (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_fd");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
fd = 0;
@@ -697,19 +1165,17 @@ weechat_python_api_hook_fd (PyObject *self, PyObject *args)
&function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_fd");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- new_hook = script_api_hook_fd (weechat_python_plugin,
- python_current_script,
- fd,
- read,
- write,
- exception,
- &weechat_python_api_hook_fd_cb,
- function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_fd (weechat_python_plugin,
+ python_current_script,
+ fd,
+ read,
+ write,
+ exception,
+ &weechat_python_api_hook_fd_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -730,7 +1196,7 @@ weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
- python_argv[0] = script_pointer_to_string (buffer);
+ python_argv[0] = script_ptr2str (buffer);
python_argv[1] = timebuffer;
python_argv[2] = prefix;
python_argv[3] = message;
@@ -763,7 +1229,6 @@ weechat_python_api_hook_print (PyObject *self, PyObject *args)
{
char *buffer, *message, *function, *result;
int strip_colors;
- struct t_hook *new_hook;
PyObject *object;
/* make C compiler happy */
@@ -772,7 +1237,7 @@ weechat_python_api_hook_print (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_print");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
buffer = NULL;
@@ -784,18 +1249,16 @@ weechat_python_api_hook_print (PyObject *self, PyObject *args)
&function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_print");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- new_hook = script_api_hook_print (weechat_python_plugin,
- python_current_script,
- script_string_to_pointer (buffer),
- message,
- strip_colors,
- &weechat_python_api_hook_print_cb,
- function);
-
- result = script_pointer_to_string(new_hook);
+ result = script_ptr2str(script_api_hook_print (weechat_python_plugin,
+ python_current_script,
+ script_str2ptr (buffer),
+ message,
+ strip_colors,
+ &weechat_python_api_hook_print_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -828,7 +1291,7 @@ weechat_python_api_hook_signal_cb (void *data, char *signal, char *type_data,
}
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
{
- python_argv[1] = script_pointer_to_string (signal_data);
+ python_argv[1] = script_ptr2str (signal_data);
free_needed = 1;
}
else
@@ -861,7 +1324,6 @@ static PyObject *
weechat_python_api_hook_signal (PyObject *self, PyObject *args)
{
char *signal, *function, *result;
- struct t_hook *new_hook;
PyObject *object;
/* make C compiler happy */
@@ -870,7 +1332,7 @@ weechat_python_api_hook_signal (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
signal = NULL;
@@ -879,16 +1341,14 @@ weechat_python_api_hook_signal (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "ss", &signal, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- new_hook = script_api_hook_signal (weechat_python_plugin,
- python_current_script,
- signal,
- &weechat_python_api_hook_signal_cb,
- function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_signal (weechat_python_plugin,
+ python_current_script,
+ signal,
+ &weechat_python_api_hook_signal_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -939,7 +1399,7 @@ weechat_python_api_hook_signal_send (PyObject *self, PyObject *args)
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
{
weechat_hook_signal_send (signal, type_data,
- script_string_to_pointer (signal_data));
+ script_str2ptr (signal_data));
PYTHON_RETURN_OK;
}
@@ -989,7 +1449,6 @@ static PyObject *
weechat_python_api_hook_config (PyObject *self, PyObject *args)
{
char *type, *option, *function, *result;
- struct t_hook *new_hook;
PyObject *object;
/* make C compiler happy */
@@ -998,7 +1457,7 @@ weechat_python_api_hook_config (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_config");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
type = NULL;
@@ -1008,17 +1467,15 @@ weechat_python_api_hook_config (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "sss", &type, &option, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_config");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- new_hook = script_api_hook_config (weechat_python_plugin,
- python_current_script,
- type,
- option,
- &weechat_python_api_hook_config_cb,
- function);
-
- result = script_pointer_to_string(new_hook);
+ result = script_ptr2str(script_api_hook_config (weechat_python_plugin,
+ python_current_script,
+ type,
+ option,
+ &weechat_python_api_hook_config_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1038,8 +1495,8 @@ weechat_python_api_hook_completion_cb (void *data, char *completion,
script_callback = (struct t_script_callback *)data;
python_argv[0] = completion;
- python_argv[1] = script_pointer_to_string (buffer);
- python_argv[2] = script_pointer_to_string (list);
+ python_argv[1] = script_ptr2str (buffer);
+ python_argv[2] = script_ptr2str (list);
python_argv[3] = NULL;
rc = (int *) weechat_python_exec (script_callback->script,
@@ -1070,7 +1527,6 @@ static PyObject *
weechat_python_api_hook_completion (PyObject *self, PyObject *args)
{
char *completion, *function, *result;
- struct t_hook *new_hook;
PyObject *object;
/* make C compiler happy */
@@ -1079,7 +1535,7 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args)
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_completion");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
completion = NULL;
@@ -1088,16 +1544,14 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "ss", &completion, &function))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- new_hook = script_api_hook_completion (weechat_python_plugin,
- python_current_script,
- completion,
- &weechat_python_api_hook_completion_cb,
- function);
-
- result = script_pointer_to_string(new_hook);
+ result = script_ptr2str(script_api_hook_completion (weechat_python_plugin,
+ python_current_script,
+ completion,
+ &weechat_python_api_hook_completion_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1129,7 +1583,7 @@ weechat_python_api_unhook (PyObject *self, PyObject *args)
if (script_api_unhook (weechat_python_plugin,
python_current_script,
- script_string_to_pointer (hook)))
+ script_str2ptr (hook)))
PYTHON_RETURN_OK;
PYTHON_RETURN_ERROR;
@@ -1172,7 +1626,7 @@ weechat_python_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- python_argv[0] = script_pointer_to_string (buffer);
+ python_argv[0] = script_ptr2str (buffer);
python_argv[1] = input_data;
python_argv[2] = NULL;
@@ -1200,7 +1654,6 @@ weechat_python_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
static PyObject *
weechat_python_api_buffer_new (PyObject *self, PyObject *args)
{
- struct t_gui_buffer *new_buffer;
char *category, *name, *function, *result;
PyObject *object;
@@ -1223,14 +1676,12 @@ weechat_python_api_buffer_new (PyObject *self, PyObject *args)
PYTHON_RETURN_EMPTY;
}
- new_buffer = script_api_buffer_new (weechat_python_plugin,
- python_current_script,
- category,
- name,
- &weechat_python_api_input_data_cb,
- function);
-
- result = script_pointer_to_string (new_buffer);
+ result = script_ptr2str (script_api_buffer_new (weechat_python_plugin,
+ python_current_script,
+ category,
+ name,
+ &weechat_python_api_input_data_cb,
+ function));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1242,7 +1693,6 @@ static PyObject *
weechat_python_api_buffer_search (PyObject *self, PyObject *args)
{
char *category, *name;
- struct t_gui_buffer *ptr_buffer;
char *result;
PyObject *object;
@@ -1264,9 +1714,7 @@ weechat_python_api_buffer_search (PyObject *self, PyObject *args)
PYTHON_RETURN_EMPTY;
}
- ptr_buffer = weechat_buffer_search (category, name);
-
- result = script_pointer_to_string (ptr_buffer);
+ result = script_ptr2str (weechat_buffer_search (category, name));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1300,7 +1748,7 @@ weechat_python_api_buffer_close (PyObject *self, PyObject *args)
script_api_buffer_close (weechat_python_plugin,
python_current_script,
- script_string_to_pointer (buffer),
+ script_str2ptr (buffer),
switch_to_another);
PYTHON_RETURN_OK;
@@ -1330,10 +1778,10 @@ weechat_python_api_buffer_get (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "ss", &buffer, &property))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("buffer_get");
- PYTHON_RETURN_ERROR;
+ PYTHON_RETURN_EMPTY;
}
- value = weechat_buffer_get (script_string_to_pointer (buffer), property);
+ value = weechat_buffer_get (script_str2ptr (buffer), property);
PYTHON_RETURN_STRING(value);
}
@@ -1365,7 +1813,7 @@ weechat_python_api_buffer_set (PyObject *self, PyObject *args)
PYTHON_RETURN_ERROR;
}
- weechat_buffer_set (script_string_to_pointer (buffer),
+ weechat_buffer_set (script_str2ptr (buffer),
property,
value);
@@ -1379,7 +1827,6 @@ weechat_python_api_buffer_set (PyObject *self, PyObject *args)
static PyObject *
weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args)
{
- struct t_gui_nick_group *new_group;
char *buffer, *parent_group, *name, *color, *result;
int visible;
PyObject *object;
@@ -1406,13 +1853,11 @@ weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args)
PYTHON_RETURN_EMPTY;
}
- new_group = weechat_nicklist_add_group (script_string_to_pointer (buffer),
- script_string_to_pointer (parent_group),
- name,
- color,
- visible);
-
- result = script_pointer_to_string (new_group);
+ result = script_ptr2str (weechat_nicklist_add_group (script_str2ptr (buffer),
+ script_str2ptr (parent_group),
+ name,
+ color,
+ visible));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1423,7 +1868,6 @@ weechat_python_api_nicklist_add_group (PyObject *self, PyObject *args)
static PyObject *
weechat_python_api_nicklist_search_group (PyObject *self, PyObject *args)
{
- struct t_gui_nick_group *ptr_group;
char *buffer, *from_group, *name, *result;
PyObject *object;
@@ -1446,11 +1890,9 @@ weechat_python_api_nicklist_search_group (PyObject *self, PyObject *args)
PYTHON_RETURN_EMPTY;
}
- ptr_group = weechat_nicklist_search_group (script_string_to_pointer (buffer),
- script_string_to_pointer (from_group),
- name);
-
- result = script_pointer_to_string (ptr_group);
+ result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr (buffer),
+ script_str2ptr (from_group),
+ name));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1461,7 +1903,6 @@ weechat_python_api_nicklist_search_group (PyObject *self, PyObject *args)
static PyObject *
weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args)
{
- struct t_gui_nick *new_nick;
char *buffer, *group, *name, *color, *prefix, *prefix_color, *result;
char char_prefix;
int visible;
@@ -1496,15 +1937,13 @@ weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args)
else
char_prefix = ' ';
- new_nick = weechat_nicklist_add_nick (script_string_to_pointer (buffer),
- script_string_to_pointer (group),
- name,
- color,
- char_prefix,
- prefix_color,
- visible);
-
- result = script_pointer_to_string (new_nick);
+ result = script_ptr2str (weechat_nicklist_add_nick (script_str2ptr (buffer),
+ script_str2ptr (group),
+ name,
+ color,
+ char_prefix,
+ prefix_color,
+ visible));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1515,7 +1954,6 @@ weechat_python_api_nicklist_add_nick (PyObject *self, PyObject *args)
static PyObject *
weechat_python_api_nicklist_search_nick (PyObject *self, PyObject *args)
{
- struct t_gui_nick *ptr_nick;
char *buffer, *from_group, *name, *result;
PyObject *object;
@@ -1538,11 +1976,9 @@ weechat_python_api_nicklist_search_nick (PyObject *self, PyObject *args)
PYTHON_RETURN_EMPTY;
}
- ptr_nick = weechat_nicklist_search_nick (script_string_to_pointer (buffer),
- script_string_to_pointer (from_group),
- name);
-
- result = script_pointer_to_string (ptr_nick);
+ result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr (buffer),
+ script_str2ptr (from_group),
+ name));
PYTHON_RETURN_STRING_FREE(result);
}
@@ -1573,8 +2009,8 @@ weechat_python_api_nicklist_remove_group (PyObject *self, PyObject *args)
PYTHON_RETURN_ERROR;
}
- weechat_nicklist_remove_group (script_string_to_pointer (buffer),
- script_string_to_pointer (group));
+ weechat_nicklist_remove_group (script_str2ptr (buffer),
+ script_str2ptr (group));
PYTHON_RETURN_OK;
}
@@ -1606,8 +2042,8 @@ weechat_python_api_nicklist_remove_nick (PyObject *self, PyObject *args)
PYTHON_RETURN_ERROR;
}
- weechat_nicklist_remove_group (script_string_to_pointer (buffer),
- script_string_to_pointer (nick));
+ weechat_nicklist_remove_group (script_str2ptr (buffer),
+ script_str2ptr (nick));
PYTHON_RETURN_OK;
}
@@ -1638,7 +2074,7 @@ weechat_python_api_nicklist_remove_all (PyObject *self, PyObject *args)
PYTHON_RETURN_ERROR;
}
- weechat_nicklist_remove_all (script_string_to_pointer (buffer));
+ weechat_nicklist_remove_all (script_str2ptr (buffer));
PYTHON_RETURN_OK;
}
@@ -1672,7 +2108,7 @@ weechat_python_api_command (PyObject *self, PyObject *args)
script_api_command (weechat_python_plugin,
python_current_script,
- script_string_to_pointer (buffer),
+ script_str2ptr (buffer),
command);
PYTHON_RETURN_OK;
@@ -2697,8 +3133,23 @@ PyMethodDef weechat_python_funcs[] =
{ "charset_set", &weechat_python_api_charset_set, METH_VARARGS, "" },
{ "iconv_to_internal", &weechat_python_api_iconv_to_internal, METH_VARARGS, "" },
{ "iconv_from_internal", &weechat_python_api_iconv_from_internal, METH_VARARGS, "" },
+ { "gettext", &weechat_python_api_gettext, METH_VARARGS, "" },
+ { "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" },
{ "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" },
{ "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" },
+ { "list_new", &weechat_python_api_list_new, METH_VARARGS, "" },
+ { "list_add", &weechat_python_api_list_add, METH_VARARGS, "" },
+ { "list_search", &weechat_python_api_list_search, METH_VARARGS, "" },
+ { "list_casesearch", &weechat_python_api_list_casesearch, METH_VARARGS, "" },
+ { "list_get", &weechat_python_api_list_get, METH_VARARGS, "" },
+ { "list_set", &weechat_python_api_list_set, METH_VARARGS, "" },
+ { "list_next", &weechat_python_api_list_next, METH_VARARGS, "" },
+ { "list_prev", &weechat_python_api_list_prev, METH_VARARGS, "" },
+ { "list_string", &weechat_python_api_list_string, METH_VARARGS, "" },
+ { "list_size", &weechat_python_api_list_size, METH_VARARGS, "" },
+ { "list_remove", &weechat_python_api_list_remove, METH_VARARGS, "" },
+ { "list_remove_all", &weechat_python_api_list_remove_all, METH_VARARGS, "" },
+ { "list_free", &weechat_python_api_list_free, METH_VARARGS, "" },
{ "prefix", &weechat_python_api_prefix, METH_VARARGS, "" },
{ "color", &weechat_python_api_color, METH_VARARGS, "" },
{ "prnt", &weechat_python_api_prnt, METH_VARARGS, "" },
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index bbf01dd09..045a10ec5 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -566,6 +566,25 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
}
/*
+ * weechat_python_completion_cb: callback for script completion
+ */
+
+int
+weechat_python_completion_cb (void *data, char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) completion;
+ (void) buffer;
+
+ script_completion (weechat_python_plugin, list, python_scripts);
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* weechat_python_dump_data_cb: dump Python plugin data in WeeChat log file
*/
@@ -621,7 +640,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
}
script_init (weechat_python_plugin,
- &weechat_python_command_cb, &weechat_python_dump_data_cb,
+ &weechat_python_command_cb,
+ &weechat_python_completion_cb,
+ &weechat_python_dump_data_cb,
&weechat_python_load_cb);
/* init ok */
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index 044961b3f..dc99704e7 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -22,13 +22,21 @@
#include <ruby.h>
+#undef PACKAGE_BUGREPORT
+#undef PACKAGE_NAME
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+#undef PACKAGE_VERSION
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include "../../weechat-plugin.h"
#include "../script.h"
#include "../script-api.h"
#include "../script-callback.h"
#include "weechat-ruby.h"
-
#define RUBY_RETURN_OK return INT2FIX (1);
#define RUBY_RETURN_ERROR return INT2FIX (0);
#define RUBY_RETURN_EMPTY return Qnil;
@@ -44,6 +52,8 @@
return return_value; \
} \
return rb_str_new2 ("")
+#define RUBY_RETURN_INT(__int) \
+ return INT2FIX(__int);
/*
@@ -76,7 +86,7 @@ weechat_ruby_api_register (VALUE class, VALUE name, VALUE author,
|| NIL_P (charset))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("register");
- return INT2FIX (0);
+ RUBY_RETURN_ERROR;
}
Check_Type (name, T_STRING);
@@ -230,7 +240,7 @@ weechat_ruby_api_iconv_from_internal (VALUE class, VALUE charset, VALUE string)
if (NIL_P (charset) || NIL_P (string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("iconv_from_internal");
- RUBY_RETURN_ERROR;
+ RUBY_RETURN_EMPTY;
}
Check_Type (charset, T_STRING);
@@ -244,6 +254,82 @@ weechat_ruby_api_iconv_from_internal (VALUE class, VALUE charset, VALUE string)
}
/*
+ * weechat_ruby_api_gettext: get translated string
+ */
+
+static VALUE
+weechat_ruby_api_gettext (VALUE class, VALUE string)
+{
+ char *c_string, *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("gettext");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_string = NULL;
+
+ if (NIL_P (string))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("gettext");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (string, T_STRING);
+
+ c_string = STR2CSTR (string);
+
+ result = weechat_gettext (c_string);
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_ngettext: get translated string with plural form
+ */
+
+static VALUE
+weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural,
+ VALUE count)
+{
+ char *c_single, *c_plural, *result;
+ int c_count;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("ngettext");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_single = NULL;
+ c_plural = NULL;
+ c_count = 0;
+
+ if (NIL_P (single) || NIL_P (plural) || NIL_P (count))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("ngettext");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (single, T_STRING);
+ Check_Type (plural, T_STRING);
+ Check_Type (count, T_FIXNUM);
+
+ c_single = STR2CSTR (single);
+ c_plural = STR2CSTR (plural);
+ c_count = FIX2INT (count);
+
+ result = weechat_ngettext (c_single, c_plural, c_count);
+ RUBY_RETURN_STRING(result);
+}
+
+/*
* weechat_ruby_api_mkdir_home: create a directory in WeeChat home
*/
@@ -324,6 +410,470 @@ weechat_ruby_api_mkdir (VALUE class, VALUE directory, VALUE mode)
}
/*
+ * weechat_ruby_api_list_new: create a new list
+ */
+
+static VALUE
+weechat_ruby_api_list_new (VALUE class)
+{
+ char *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_new");
+ RUBY_RETURN_EMPTY;
+ }
+
+ result = script_ptr2str (weechat_list_new ());
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_add: add a string to list
+ */
+
+static VALUE
+weechat_ruby_api_list_add (VALUE class, VALUE weelist, VALUE data, VALUE where)
+{
+ char *c_weelist, *c_data, *c_where, *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_add");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_weelist = NULL;
+ c_data = NULL;
+ c_where = NULL;
+
+ if (NIL_P (weelist) || NIL_P (data) || NIL_P (where))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (weelist, T_STRING);
+ Check_Type (data, T_STRING);
+ Check_Type (where, T_STRING);
+
+ c_weelist = STR2CSTR (weelist);
+ c_data = STR2CSTR (data);
+ c_where = STR2CSTR (where);
+
+ result = script_ptr2str (weechat_list_add (script_str2ptr(c_weelist),
+ c_data,
+ c_where));
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_search: search a string in list
+ */
+
+static VALUE
+weechat_ruby_api_list_search (VALUE class, VALUE weelist, VALUE data)
+{
+ char *c_weelist, *c_data, *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_search");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_weelist = NULL;
+ c_data = NULL;
+
+ if (NIL_P (weelist) || NIL_P (data))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_search");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (weelist, T_STRING);
+ Check_Type (data, T_STRING);
+
+ c_weelist = STR2CSTR (weelist);
+ c_data = STR2CSTR (data);
+
+ result = script_ptr2str (weechat_list_search (script_str2ptr(c_weelist),
+ c_data));
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_casesearch: search a string in list (ignore case)
+ */
+
+static VALUE
+weechat_ruby_api_list_casesearch (VALUE class, VALUE weelist, VALUE data)
+{
+ char *c_weelist, *c_data, *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_casesearch");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_weelist = NULL;
+ c_data = NULL;
+
+ if (NIL_P (weelist) || NIL_P (data))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_casesearch");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (weelist, T_STRING);
+ Check_Type (data, T_STRING);
+
+ c_weelist = STR2CSTR (weelist);
+ c_data = STR2CSTR (data);
+
+ result = script_ptr2str (weechat_list_casesearch (script_str2ptr(c_weelist),
+ c_data));
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_get: get item by position
+ */
+
+static VALUE
+weechat_ruby_api_list_get (VALUE class, VALUE weelist, VALUE position)
+{
+ char *c_weelist, *result;
+ int c_position;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_get");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_weelist = NULL;
+ c_position = 0;
+
+ if (NIL_P (weelist) || NIL_P (position))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_get");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (weelist, T_STRING);
+ Check_Type (position, T_FIXNUM);
+
+ c_weelist = STR2CSTR (weelist);
+ c_position = FIX2INT (position);
+
+ result = script_ptr2str (weechat_list_get (script_str2ptr(c_weelist),
+ c_position));
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_set: set new value for item
+ */
+
+static VALUE
+weechat_ruby_api_list_set (VALUE class, VALUE item, VALUE new_value)
+{
+ char *c_item, *c_new_value;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_set");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_item = NULL;
+ c_new_value = NULL;
+
+ if (NIL_P (item) || NIL_P (new_value))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_set");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (item, T_STRING);
+ Check_Type (new_value, T_STRING);
+
+ c_item = STR2CSTR (item);
+ c_new_value = STR2CSTR (new_value);
+
+ weechat_list_set (script_str2ptr(c_item),
+ c_new_value);
+
+ RUBY_RETURN_OK;
+}
+
+/*
+ * weechat_ruby_api_list_next: get next item
+ */
+
+static VALUE
+weechat_ruby_api_list_next (VALUE class, VALUE item)
+{
+ char *c_item, *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_next");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_item = NULL;
+
+ if (NIL_P (item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_next");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (item, T_STRING);
+
+ c_item = STR2CSTR (item);
+
+ result = script_ptr2str (weechat_list_next (script_str2ptr(c_item)));
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_prev: get previous item
+ */
+
+static VALUE
+weechat_ruby_api_list_prev (VALUE class, VALUE item)
+{
+ char *c_item, *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_prev");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_item = NULL;
+
+ if (NIL_P (item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_prev");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (item, T_STRING);
+
+ c_item = STR2CSTR (item);
+
+ result = script_ptr2str (weechat_list_prev (script_str2ptr(c_item)));
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_string: get string value of item
+ */
+
+static VALUE
+weechat_ruby_api_list_string (VALUE class, VALUE item)
+{
+ char *c_item, *result;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_string");
+ RUBY_RETURN_EMPTY;
+ }
+
+ c_item = NULL;
+
+ if (NIL_P (item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_string");
+ RUBY_RETURN_EMPTY;
+ }
+
+ Check_Type (item, T_STRING);
+
+ c_item = STR2CSTR (item);
+
+ result = weechat_list_string (script_str2ptr(c_item));
+ RUBY_RETURN_STRING(result);
+}
+
+/*
+ * weechat_ruby_api_list_size: get number of elements in list
+ */
+
+static VALUE
+weechat_ruby_api_list_size (VALUE class, VALUE weelist)
+{
+ char *c_weelist;
+ int size;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_size");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_weelist = NULL;
+
+ if (NIL_P (weelist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_size");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (weelist, T_STRING);
+
+ c_weelist = STR2CSTR (weelist);
+
+ size = weechat_list_size (script_str2ptr(c_weelist));
+ RUBY_RETURN_INT(size);
+}
+
+/*
+ * weechat_ruby_api_list_remove: remove item from list
+ */
+
+static VALUE
+weechat_ruby_api_list_remove (VALUE class, VALUE weelist, VALUE item)
+{
+ char *c_weelist, *c_item;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_weelist = NULL;
+ c_item = NULL;
+
+ if (NIL_P (weelist) || NIL_P (item))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (weelist, T_STRING);
+ Check_Type (item, T_STRING);
+
+ c_weelist = STR2CSTR (weelist);
+ c_item = STR2CSTR (item);
+
+ weechat_list_remove (script_str2ptr (c_weelist),
+ script_str2ptr (c_item));
+
+ RUBY_RETURN_OK;
+}
+
+/*
+ * weechat_ruby_api_list_remove_all: remove all items from list
+ */
+
+static VALUE
+weechat_ruby_api_list_remove_all (VALUE class, VALUE weelist)
+{
+ char *c_weelist;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_remove_all");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_weelist = NULL;
+
+ if (NIL_P (weelist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_remove_all");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (weelist, T_STRING);
+
+ c_weelist = STR2CSTR (weelist);
+
+ weechat_list_remove_all (script_str2ptr (c_weelist));
+
+ RUBY_RETURN_OK;
+}
+
+/*
+ * weechat_ruby_api_list_free: free list
+ */
+
+static VALUE
+weechat_ruby_api_list_free (VALUE class, VALUE weelist)
+{
+ char *c_weelist;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_free");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_weelist = NULL;
+
+ if (NIL_P (weelist))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_free");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (weelist, T_STRING);
+
+ c_weelist = STR2CSTR (weelist);
+
+ weechat_list_free (script_str2ptr (c_weelist));
+
+ RUBY_RETURN_OK;
+}
+
+/*
* weechat_ruby_api_prefix: get a prefix, used for display
*/
@@ -426,7 +976,7 @@ weechat_ruby_api_print (VALUE class, VALUE buffer, VALUE message)
script_api_printf (weechat_ruby_plugin,
ruby_current_script,
- script_string_to_pointer (c_buffer),
+ script_str2ptr (c_buffer),
"%s", c_message);
RUBY_RETURN_OK;
@@ -567,7 +1117,7 @@ weechat_ruby_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- ruby_argv[0] = script_pointer_to_string (buffer);
+ ruby_argv[0] = script_ptr2str (buffer);
ruby_argv[1] = (argc > 1) ? argv_eol[1] : empty_arg;
ruby_argv[2] = NULL;
@@ -600,7 +1150,6 @@ weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description,
{
char *c_command, *c_description, *c_args, *c_args_description;
char *c_completion, *c_function, *result;
- struct t_hook *new_hook;
VALUE return_value;
/* make C compiler happy */
@@ -640,17 +1189,15 @@ weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description,
c_completion = STR2CSTR (completion);
c_function = STR2CSTR (function);
- new_hook = script_api_hook_command (weechat_ruby_plugin,
- ruby_current_script,
- c_command,
- c_description,
- c_args,
- c_args_description,
- c_completion,
- &weechat_ruby_api_hook_command_cb,
- c_function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_command (weechat_ruby_plugin,
+ ruby_current_script,
+ c_command,
+ c_description,
+ c_args,
+ c_args_description,
+ c_completion,
+ &weechat_ruby_api_hook_command_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -693,7 +1240,6 @@ weechat_ruby_api_hook_timer (VALUE class, VALUE interval, VALUE align_second,
{
int c_interval, c_align_second, c_max_calls;
char *c_function, *result;
- struct t_hook *new_hook;
VALUE return_value;
/* make C compiler happy */
@@ -727,15 +1273,13 @@ weechat_ruby_api_hook_timer (VALUE class, VALUE interval, VALUE align_second,
c_max_calls = FIX2INT (max_calls);
c_function = STR2CSTR (function);
- new_hook = script_api_hook_timer (weechat_ruby_plugin,
- ruby_current_script,
- c_interval,
- c_align_second,
- c_max_calls,
- &weechat_ruby_api_hook_timer_cb,
- c_function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_timer (weechat_ruby_plugin,
+ ruby_current_script,
+ c_interval,
+ c_align_second,
+ c_max_calls,
+ &weechat_ruby_api_hook_timer_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -778,7 +1322,6 @@ weechat_ruby_api_hook_fd (VALUE class, VALUE fd, VALUE read, VALUE write,
{
int c_fd, c_read, c_write, c_exception;
char *c_function, *result;
- struct t_hook *new_hook;
VALUE return_value;
/* make C compiler happy */
@@ -815,16 +1358,14 @@ weechat_ruby_api_hook_fd (VALUE class, VALUE fd, VALUE read, VALUE write,
c_exception = FIX2INT (exception);
c_function = STR2CSTR (function);
- new_hook = script_api_hook_fd (weechat_ruby_plugin,
- ruby_current_script,
- c_fd,
- c_read,
- c_write,
- c_exception,
- &weechat_ruby_api_hook_fd_cb,
- c_function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_fd (weechat_ruby_plugin,
+ ruby_current_script,
+ c_fd,
+ c_read,
+ c_write,
+ c_exception,
+ &weechat_ruby_api_hook_fd_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -845,7 +1386,7 @@ weechat_ruby_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
snprintf (timebuffer, sizeof (timebuffer) - 1, "%ld", date);
- ruby_argv[0] = script_pointer_to_string (buffer);
+ ruby_argv[0] = script_ptr2str (buffer);
ruby_argv[1] = timebuffer;
ruby_argv[2] = prefix;
ruby_argv[3] = message;
@@ -879,7 +1420,6 @@ weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE message,
{
char *c_buffer, *c_message, *c_function, *result;
int c_strip_colors;
- struct t_hook *new_hook;
VALUE return_value;
/* make C compiler happy */
@@ -913,15 +1453,13 @@ weechat_ruby_api_hook_print (VALUE class, VALUE buffer, VALUE message,
c_strip_colors = FIX2INT (strip_colors);
c_function = STR2CSTR (function);
- new_hook = script_api_hook_print (weechat_ruby_plugin,
- ruby_current_script,
- script_string_to_pointer (c_buffer),
- c_message,
- c_strip_colors,
- &weechat_ruby_api_hook_print_cb,
- c_function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_print (weechat_ruby_plugin,
+ ruby_current_script,
+ script_str2ptr (c_buffer),
+ c_message,
+ c_strip_colors,
+ &weechat_ruby_api_hook_print_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -954,7 +1492,7 @@ weechat_ruby_api_hook_signal_cb (void *data, char *signal, char *type_data,
}
else if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_POINTER) == 0)
{
- ruby_argv[1] = script_pointer_to_string (signal_data);
+ ruby_argv[1] = script_ptr2str (signal_data);
free_needed = 1;
}
else
@@ -987,7 +1525,6 @@ static VALUE
weechat_ruby_api_hook_signal (VALUE class, VALUE signal, VALUE function)
{
char *c_signal, *c_function, *result;
- struct t_hook *new_hook;
VALUE return_value;
/* make C compiler happy */
@@ -1014,13 +1551,11 @@ weechat_ruby_api_hook_signal (VALUE class, VALUE signal, VALUE function)
c_signal = STR2CSTR (signal);
c_function = STR2CSTR (function);
- new_hook = script_api_hook_signal (weechat_ruby_plugin,
- ruby_current_script,
- c_signal,
- &weechat_ruby_api_hook_signal_cb,
- c_function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_signal (weechat_ruby_plugin,
+ ruby_current_script,
+ c_signal,
+ &weechat_ruby_api_hook_signal_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1041,7 +1576,7 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_signal_send");
- RUBY_RETURN_EMPTY;
+ RUBY_RETURN_ERROR;
}
c_signal = NULL;
@@ -1051,7 +1586,7 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
if (NIL_P (signal) || NIL_P (type_data) || NIL_P (signal_data))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_signal_send");
- RUBY_RETURN_EMPTY;
+ RUBY_RETURN_ERROR;
}
Check_Type (signal, T_STRING);
@@ -1079,7 +1614,7 @@ weechat_ruby_api_hook_signal_send (VALUE class, VALUE signal, VALUE type_data,
Check_Type (signal_data, T_STRING);
c_signal_data = STR2CSTR (signal_data);
weechat_hook_signal_send (c_signal, c_type_data,
- script_string_to_pointer (c_signal_data));
+ script_str2ptr (c_signal_data));
RUBY_RETURN_OK;
}
@@ -1126,10 +1661,10 @@ weechat_ruby_api_hook_config_cb (void *data, char *type, char *option,
*/
static VALUE
-weechat_ruby_api_hook_config (VALUE class, VALUE type, VALUE option, VALUE function)
+weechat_ruby_api_hook_config (VALUE class, VALUE type, VALUE option,
+ VALUE function)
{
char *c_type, *c_option, *c_function, *result;
- struct t_hook *new_hook;
VALUE return_value;
/* make C compiler happy */
@@ -1159,14 +1694,12 @@ weechat_ruby_api_hook_config (VALUE class, VALUE type, VALUE option, VALUE funct
c_option = STR2CSTR (option);
c_function = STR2CSTR (function);
- new_hook = script_api_hook_config (weechat_ruby_plugin,
- ruby_current_script,
- c_type,
- c_option,
- &weechat_ruby_api_hook_config_cb,
- c_function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_config (weechat_ruby_plugin,
+ ruby_current_script,
+ c_type,
+ c_option,
+ &weechat_ruby_api_hook_config_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1186,8 +1719,8 @@ weechat_ruby_api_hook_completion_cb (void *data, char *completion,
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = completion;
- ruby_argv[1] = script_pointer_to_string (buffer);
- ruby_argv[2] = script_pointer_to_string (list);
+ ruby_argv[1] = script_ptr2str (buffer);
+ ruby_argv[2] = script_ptr2str (list);
ruby_argv[3] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
@@ -1215,10 +1748,10 @@ weechat_ruby_api_hook_completion_cb (void *data, char *completion,
*/
static VALUE
-weechat_ruby_api_hook_completion (VALUE class, VALUE completion, VALUE function)
+weechat_ruby_api_hook_completion (VALUE class, VALUE completion,
+ VALUE function)
{
char *c_completion, *c_function, *result;
- struct t_hook *new_hook;
VALUE return_value;
/* make C compiler happy */
@@ -1245,13 +1778,11 @@ weechat_ruby_api_hook_completion (VALUE class, VALUE completion, VALUE function)
c_completion = STR2CSTR (completion);
c_function = STR2CSTR (function);
- new_hook = script_api_hook_completion (weechat_ruby_plugin,
- ruby_current_script,
- c_completion,
- &weechat_ruby_api_hook_completion_cb,
- c_function);
-
- result = script_pointer_to_string (new_hook);
+ result = script_ptr2str (script_api_hook_completion (weechat_ruby_plugin,
+ ruby_current_script,
+ c_completion,
+ &weechat_ruby_api_hook_completion_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1278,7 +1809,7 @@ weechat_ruby_api_unhook (VALUE class, VALUE hook)
if (NIL_P (hook))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("unhook");
- RUBY_RETURN_EMPTY;
+ RUBY_RETURN_ERROR;
}
Check_Type (hook, T_STRING);
@@ -1287,7 +1818,7 @@ weechat_ruby_api_unhook (VALUE class, VALUE hook)
if (script_api_unhook (weechat_ruby_plugin,
ruby_current_script,
- script_string_to_pointer (c_hook)))
+ script_str2ptr (c_hook)))
RUBY_RETURN_OK;
RUBY_RETURN_ERROR;
@@ -1329,7 +1860,7 @@ weechat_ruby_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
script_callback = (struct t_script_callback *)data;
- ruby_argv[0] = script_pointer_to_string (buffer);
+ ruby_argv[0] = script_ptr2str (buffer);
ruby_argv[1] = input_data;
ruby_argv[2] = NULL;
@@ -1356,10 +1887,10 @@ weechat_ruby_api_input_data_cb (void *data, struct t_gui_buffer *buffer,
*/
static VALUE
-weechat_ruby_api_buffer_new (VALUE class, VALUE category, VALUE name, VALUE function)
+weechat_ruby_api_buffer_new (VALUE class, VALUE category, VALUE name,
+ VALUE function)
{
char *c_category, *c_name, *c_function, *result;
- struct t_gui_buffer *new_buffer;
VALUE return_value;
/* make C compiler happy */
@@ -1389,14 +1920,12 @@ weechat_ruby_api_buffer_new (VALUE class, VALUE category, VALUE name, VALUE func
c_name = STR2CSTR (name);
c_function = STR2CSTR (function);
- new_buffer = script_api_buffer_new (weechat_ruby_plugin,
- ruby_current_script,
- c_category,
- c_name,
- &weechat_ruby_api_input_data_cb,
- c_function);
-
- result = script_pointer_to_string (new_buffer);
+ result = script_ptr2str (script_api_buffer_new (weechat_ruby_plugin,
+ ruby_current_script,
+ c_category,
+ c_name,
+ &weechat_ruby_api_input_data_cb,
+ c_function));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1408,7 +1937,6 @@ static VALUE
weechat_ruby_api_buffer_search (VALUE class, VALUE category, VALUE name)
{
char *c_category, *c_name, *result;
- struct t_gui_buffer *ptr_buffer;
VALUE return_value;
/* make C compiler happy */
@@ -1435,9 +1963,7 @@ weechat_ruby_api_buffer_search (VALUE class, VALUE category, VALUE name)
c_category = STR2CSTR (category);
c_name = STR2CSTR (name);
- ptr_buffer = weechat_buffer_search (c_category, c_name);
-
- result = script_pointer_to_string (ptr_buffer);
+ result = script_ptr2str (weechat_buffer_search (c_category, c_name));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1446,7 +1972,8 @@ weechat_ruby_api_buffer_search (VALUE class, VALUE category, VALUE name)
*/
static VALUE
-weechat_ruby_api_buffer_close (VALUE class, VALUE buffer, VALUE switch_to_another)
+weechat_ruby_api_buffer_close (VALUE class, VALUE buffer,
+ VALUE switch_to_another)
{
char *c_buffer;
int c_switch_to_another;
@@ -1477,7 +2004,7 @@ weechat_ruby_api_buffer_close (VALUE class, VALUE buffer, VALUE switch_to_anothe
script_api_buffer_close (weechat_ruby_plugin,
ruby_current_script,
- script_string_to_pointer (c_buffer),
+ script_str2ptr (c_buffer),
c_switch_to_another);
RUBY_RETURN_OK;
@@ -1513,7 +2040,7 @@ weechat_ruby_api_buffer_get (VALUE class, VALUE buffer, VALUE property)
c_buffer = STR2CSTR (buffer);
c_property = STR2CSTR (property);
- value = weechat_buffer_get (script_string_to_pointer (c_buffer),
+ value = weechat_buffer_get (script_str2ptr (c_buffer),
c_property);
RUBY_RETURN_STRING(value);
}
@@ -1523,7 +2050,8 @@ weechat_ruby_api_buffer_get (VALUE class, VALUE buffer, VALUE property)
*/
static VALUE
-weechat_ruby_api_buffer_set (VALUE class, VALUE buffer, VALUE property, VALUE value)
+weechat_ruby_api_buffer_set (VALUE class, VALUE buffer, VALUE property,
+ VALUE value)
{
char *c_buffer, *c_property, *c_value;
@@ -1550,7 +2078,7 @@ weechat_ruby_api_buffer_set (VALUE class, VALUE buffer, VALUE property, VALUE va
c_property = STR2CSTR (property);
c_value = STR2CSTR (value);
- weechat_buffer_set (script_string_to_pointer (c_buffer),
+ weechat_buffer_set (script_str2ptr (c_buffer),
c_property,
c_value);
@@ -1568,7 +2096,6 @@ weechat_ruby_api_nicklist_add_group (VALUE class, VALUE buffer,
{
char *c_buffer, *c_parent_group, *c_name, *c_color, *result;
int c_visible;
- struct t_gui_nick_group *new_group;
VALUE return_value;
/* make C compiler happy */
@@ -1605,13 +2132,11 @@ weechat_ruby_api_nicklist_add_group (VALUE class, VALUE buffer,
c_color = STR2CSTR (color);
c_visible = FIX2INT (visible);
- new_group = weechat_nicklist_add_group (script_string_to_pointer (c_buffer),
- script_string_to_pointer (c_parent_group),
- c_name,
- c_color,
- c_visible);
-
- result = script_pointer_to_string (new_group);
+ result = script_ptr2str (weechat_nicklist_add_group (script_str2ptr (c_buffer),
+ script_str2ptr (c_parent_group),
+ c_name,
+ c_color,
+ c_visible));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1624,7 +2149,6 @@ weechat_ruby_api_nicklist_search_group (VALUE class, VALUE buffer,
VALUE from_group, VALUE name)
{
char *c_buffer, *c_from_group, *c_name, *result;
- struct t_gui_nick_group *ptr_group;
VALUE return_value;
/* make C compiler happy */
@@ -1654,11 +2178,9 @@ weechat_ruby_api_nicklist_search_group (VALUE class, VALUE buffer,
c_from_group = STR2CSTR (from_group);
c_name = STR2CSTR (name);
- ptr_group = weechat_nicklist_search_group (script_string_to_pointer (c_buffer),
- script_string_to_pointer (c_from_group),
- c_name);
-
- result = script_pointer_to_string (ptr_group);
+ result = script_ptr2str (weechat_nicklist_search_group (script_str2ptr (c_buffer),
+ script_str2ptr (c_from_group),
+ c_name));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1674,7 +2196,6 @@ weechat_ruby_api_nicklist_add_nick (VALUE class, VALUE buffer, VALUE group,
char *c_buffer, *c_group, *c_name, *c_color, *c_prefix, char_prefix;
char *c_prefix_color, *result;
int c_visible;
- struct t_gui_nick *new_nick;
VALUE return_value;
/* make C compiler happy */
@@ -1722,15 +2243,13 @@ weechat_ruby_api_nicklist_add_nick (VALUE class, VALUE buffer, VALUE group,
else
char_prefix = ' ';
- new_nick = weechat_nicklist_add_nick (script_string_to_pointer (c_buffer),
- script_string_to_pointer (c_group),
- c_name,
- c_color,
- char_prefix,
- c_prefix_color,
- c_visible);
-
- result = script_pointer_to_string (new_nick);
+ result = script_ptr2str (weechat_nicklist_add_nick (script_str2ptr (c_buffer),
+ script_str2ptr (c_group),
+ c_name,
+ c_color,
+ char_prefix,
+ c_prefix_color,
+ c_visible));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1743,7 +2262,6 @@ weechat_ruby_api_nicklist_search_nick (VALUE class, VALUE buffer,
VALUE from_group, VALUE name)
{
char *c_buffer, *c_from_group, *c_name, *result;
- struct t_gui_nick *ptr_nick;
VALUE return_value;
/* make C compiler happy */
@@ -1773,11 +2291,9 @@ weechat_ruby_api_nicklist_search_nick (VALUE class, VALUE buffer,
c_from_group = STR2CSTR (from_group);
c_name = STR2CSTR (name);
- ptr_nick = weechat_nicklist_search_nick (script_string_to_pointer (c_buffer),
- script_string_to_pointer (c_from_group),
- c_name);
-
- result = script_pointer_to_string (ptr_nick);
+ result = script_ptr2str (weechat_nicklist_search_nick (script_str2ptr (c_buffer),
+ script_str2ptr (c_from_group),
+ c_name));
RUBY_RETURN_STRING_FREE(result);
}
@@ -1811,8 +2327,8 @@ weechat_ruby_api_nicklist_remove_group (VALUE class, VALUE buffer, VALUE group)
c_buffer = STR2CSTR (buffer);
c_group = STR2CSTR (group);
- weechat_nicklist_remove_group (script_string_to_pointer (c_buffer),
- script_string_to_pointer (c_group));
+ weechat_nicklist_remove_group (script_str2ptr (c_buffer),
+ script_str2ptr (c_group));
RUBY_RETURN_OK;
}
@@ -1847,8 +2363,8 @@ weechat_ruby_api_nicklist_remove_nick (VALUE class, VALUE buffer, VALUE nick)
c_buffer = STR2CSTR (buffer);
c_nick = STR2CSTR (nick);
- weechat_nicklist_remove_nick (script_string_to_pointer (c_buffer),
- script_string_to_pointer (c_nick));
+ weechat_nicklist_remove_nick (script_str2ptr (c_buffer),
+ script_str2ptr (c_nick));
RUBY_RETURN_OK;
}
@@ -1881,7 +2397,7 @@ weechat_ruby_api_nicklist_remove_all (VALUE class, VALUE buffer)
c_buffer = STR2CSTR (buffer);
- weechat_nicklist_remove_all (script_string_to_pointer (c_buffer));
+ weechat_nicklist_remove_all (script_str2ptr (c_buffer));
RUBY_RETURN_OK;
}
@@ -1918,7 +2434,7 @@ weechat_ruby_api_command (VALUE class, VALUE buffer, VALUE command)
script_api_command (weechat_ruby_plugin,
ruby_current_script,
- script_string_to_pointer (c_buffer),
+ script_str2ptr (c_buffer),
c_command);
RUBY_RETURN_OK;
@@ -1945,7 +2461,7 @@ weechat_ruby_api_info_get (VALUE class, VALUE info)
if (NIL_P (info))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("info_get");
- RUBY_RETURN_ERROR;
+ RUBY_RETURN_EMPTY;
}
Check_Type (info, T_STRING);
@@ -2762,8 +3278,23 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "charset_set", &weechat_ruby_api_charset_set, 1);
rb_define_module_function (ruby_mWeechat, "iconv_to_internal", &weechat_ruby_api_iconv_to_internal, 2);
rb_define_module_function (ruby_mWeechat, "iconv_from_internal", &weechat_ruby_api_iconv_from_internal, 2);
+ rb_define_module_function (ruby_mWeechat, "gettext", &weechat_ruby_api_gettext, 1);
+ rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3);
rb_define_module_function (ruby_mWeechat, "mkdir_home", &weechat_ruby_api_mkdir_home, 2);
rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2);
+ rb_define_module_function (ruby_mWeechat, "list_new", &weechat_ruby_api_list_new, 0);
+ rb_define_module_function (ruby_mWeechat, "list_add", &weechat_ruby_api_list_add, 3);
+ rb_define_module_function (ruby_mWeechat, "list_search", &weechat_ruby_api_list_search, 2);
+ rb_define_module_function (ruby_mWeechat, "list_casesearch", &weechat_ruby_api_list_casesearch, 2);
+ rb_define_module_function (ruby_mWeechat, "list_get", &weechat_ruby_api_list_get, 2);
+ rb_define_module_function (ruby_mWeechat, "list_set", &weechat_ruby_api_list_set, 2);
+ rb_define_module_function (ruby_mWeechat, "list_next", &weechat_ruby_api_list_next, 1);
+ rb_define_module_function (ruby_mWeechat, "list_prev", &weechat_ruby_api_list_prev, 1);
+ rb_define_module_function (ruby_mWeechat, "list_string", &weechat_ruby_api_list_string, 1);
+ rb_define_module_function (ruby_mWeechat, "list_size", &weechat_ruby_api_list_size, 1);
+ rb_define_module_function (ruby_mWeechat, "list_remove", &weechat_ruby_api_list_remove, 2);
+ rb_define_module_function (ruby_mWeechat, "list_remove_all", &weechat_ruby_api_list_remove_all, 1);
+ rb_define_module_function (ruby_mWeechat, "list_free", &weechat_ruby_api_list_free, 1);
rb_define_module_function (ruby_mWeechat, "prefix", &weechat_ruby_api_prefix, 1);
rb_define_module_function (ruby_mWeechat, "color", &weechat_ruby_api_color, 1);
rb_define_module_function (ruby_mWeechat, "print", &weechat_ruby_api_print, 2);
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index 07d499447..ad420c0ca 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -25,6 +25,15 @@
#include <sys/types.h>
#include <sys/stat.h>
+#undef PACKAGE_BUGREPORT
+#undef PACKAGE_NAME
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+#undef PACKAGE_VERSION
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include "../../weechat-plugin.h"
#include "../script.h"
#include "weechat-ruby.h"
@@ -563,6 +572,25 @@ weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer,
}
/*
+ * weechat_ruby_completion_cb: callback for script completion
+ */
+
+int
+weechat_ruby_completion_cb (void *data, char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) completion;
+ (void) buffer;
+
+ script_completion (weechat_ruby_plugin, list, ruby_scripts);
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* weechat_ruby_dump_data_cb: dump Ruby plugin data in WeeChat log file
*/
@@ -669,7 +697,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
}
script_init (weechat_ruby_plugin,
- &weechat_ruby_command_cb, &weechat_ruby_dump_data_cb,
+ &weechat_ruby_command_cb,
+ &weechat_ruby_completion_cb,
+ &weechat_ruby_dump_data_cb,
&weechat_ruby_load_cb);
/* init ok */
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index b864e6e83..b264b2aea 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -85,12 +85,15 @@ script_init (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer,
int argc, char **argv,
char **argv_eol),
+ int (*callback_completion)(void *data, char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list),
int (*callback_signal_dump)(void *data, char *signal,
char *type_data,
void *signal_data),
int (*callback_load_file)(void *data, char *filename))
{
- char *string;
+ char *string, *completion = "list|listfull|load|autoload|reload|unload %f";
int length;
/* read script configuration */
@@ -120,6 +123,13 @@ script_init (struct t_weechat_plugin *weechat_plugin,
}
/* add command */
+ length = strlen (completion) + strlen (weechat_plugin->name) + 16;
+ string = (char *)malloc (length);
+ if (string)
+ {
+ snprintf (string, length, "%s|%%(%s_script)",
+ completion, weechat_plugin->name);
+ }
weechat_hook_command (weechat_plugin->name,
_("list/load/unload scripts"),
_("[list [name]] | [listfull [name]] "
@@ -129,8 +139,20 @@ script_init (struct t_weechat_plugin *weechat_plugin,
"name: a script name\n\n"
"Without argument, this command "
"lists all loaded scripts."),
- "list|listfull|load|autoload|reload|unload %f",
+ (string) ? string : completion,
callback_command, NULL);
+ if (string)
+ free (string);
+
+ /* add completion */
+ length = strlen (weechat_plugin->name) + 16;
+ string = (char *)malloc (length);
+ if (string)
+ {
+ snprintf (string, length, "%s_script", weechat_plugin->name);
+ weechat_hook_completion (string, callback_completion, NULL);
+ free (string);
+ }
/* add signal for "dump_data" */
weechat_hook_signal ("dump_data", callback_signal_dump, NULL);
@@ -140,13 +162,13 @@ script_init (struct t_weechat_plugin *weechat_plugin,
}
/*
- * script_pointer_to_string: convert pointer to string for usage
- * in a script (any language)
- * WARNING: result has to be free() after use
+ * script_ptr2str: convert pointer to string for usage in a script
+ * (any language)
+ * WARNING: result has to be free() after use
*/
char *
-script_pointer_to_string (void *pointer)
+script_ptr2str (void *pointer)
{
char pointer_str[128];
@@ -160,12 +182,11 @@ script_pointer_to_string (void *pointer)
}
/*
- * script_string_to_pointer: convert stirng to pointer for usage
- * outside script
+ * script_str2ptr: convert stirng to pointer for usage outside script
*/
void *
-script_string_to_pointer (char *pointer_str)
+script_str2ptr (char *pointer_str)
{
unsigned int value;
@@ -420,6 +441,24 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
}
/*
+ * script_completion: complete with list of scripts
+ */
+
+void
+script_completion (struct t_weechat_plugin *weechat_plugin,
+ struct t_weelist *list,
+ struct t_plugin_script *scripts)
+{
+ struct t_plugin_script *ptr_script;
+
+ for (ptr_script = scripts; ptr_script;
+ ptr_script = ptr_script->next_script)
+ {
+ weechat_list_add (list, ptr_script->name, WEECHAT_LIST_POS_SORT);
+ }
+}
+
+/*
* script_display_list: print list of scripts
*/
diff --git a/src/plugins/scripts/script.h b/src/plugins/scripts/script.h
index 59ee51eef..badc16c6f 100644
--- a/src/plugins/scripts/script.h
+++ b/src/plugins/scripts/script.h
@@ -61,12 +61,15 @@ extern void script_init (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer,
int argc, char **argv,
char **argv_eol),
+ int (*callback_completion)(void *data, char *completion,
+ struct t_gui_buffer *buffer,
+ struct t_weelist *list),
int (*callback_signal_dump)(void *data, char *signal,
char *type_data,
void *signal_data),
int (*callback_load_file)(void *data, char *filename));
-extern char *script_pointer_to_string (void *pointer);
-extern void *script_string_to_pointer (char *pointer_str);
+extern char *script_ptr2str (void *pointer);
+extern void *script_str2ptr (char *pointer_str);
extern void script_auto_load (struct t_weechat_plugin *weechat_plugin,
int (*callback)(void *data, char *filename));
extern struct t_plugin_script *script_search (struct t_weechat_plugin *weechat_plugin,
@@ -83,6 +86,9 @@ extern struct t_plugin_script *script_add (struct t_weechat_plugin *weechat_plug
extern void script_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script **scripts,
struct t_plugin_script *script);
+extern void script_completion (struct t_weechat_plugin *weechat_plugin,
+ struct t_weelist *list,
+ struct t_plugin_script *scripts);
extern void script_display_list (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *scripts,
char *name, int full);