summaryrefslogtreecommitdiff
path: root/src/plugins/perl
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-11-02 09:37:15 +0100
committerSebastien Helleu <flashcode@flashtux.org>2012-11-02 09:37:15 +0100
commit32c93b5c0a3abd2525677e0e2615abde8460d693 (patch)
treebb7377366ff48325d31cc2c3caecc1be3c88400f /src/plugins/perl
parent3ec0ad7c62279af13fcc6ee3ef78b11dcc3be382 (diff)
downloadweechat-32c93b5c0a3abd2525677e0e2615abde8460d693.zip
core: add command /eval, use expression in conditions for bars, add function "string_eval_expression" in plugin API
Diffstat (limited to 'src/plugins/perl')
-rw-r--r--src/plugins/perl/weechat-perl-api.c55
-rw-r--r--src/plugins/perl/weechat-perl.c25
-rw-r--r--src/plugins/perl/weechat-perl.h5
3 files changed, 70 insertions, 15 deletions
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index 3d0cb645e..d182bbb04 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -437,6 +437,40 @@ XS (XS_weechat_api_string_input_for_buffer)
}
/*
+ * weechat::string_eval_expression: evaluate expression and return result
+ */
+
+XS (XS_weechat_api_string_eval_expression)
+{
+ char *expr, *result;
+ struct t_hashtable *pointers, *extra_vars;
+ dXSARGS;
+
+ API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
+ if (items < 3)
+ API_WRONG_ARGS(API_RETURN_EMPTY);
+
+ expr = SvPV_nolen (ST (0));
+ pointers = weechat_perl_hash_to_hashtable (ST (1),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER);
+ extra_vars = weechat_perl_hash_to_hashtable (ST (2),
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
+
+ result = weechat_string_eval_expression (expr, pointers, extra_vars);
+
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (extra_vars)
+ weechat_hashtable_free (extra_vars);
+
+ API_RETURN_STRING_FREE(result);
+}
+
+/*
* weechat::mkdir_home: create a directory in WeeChat home
*/
@@ -2003,7 +2037,9 @@ XS (XS_weechat_api_key_bind)
context = SvPV_nolen (ST (0));
hashtable = weechat_perl_hash_to_hashtable (ST (1),
- WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
num_keys = weechat_key_bind (context, hashtable);
@@ -2537,7 +2573,9 @@ XS (XS_weechat_api_hook_process_hashtable)
command = SvPV_nolen (ST (0));
options = weechat_perl_hash_to_hashtable (ST (1),
- WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
function = SvPV_nolen (ST (3));
data = SvPV_nolen (ST (4));
@@ -2951,7 +2989,9 @@ XS (XS_weechat_api_hook_hsignal_send)
signal = SvPV_nolen (ST (0));
hashtable = weechat_perl_hash_to_hashtable (ST (1),
- WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
weechat_hook_hsignal_send (signal, hashtable);
@@ -4663,7 +4703,9 @@ XS (XS_weechat_api_info_get_hashtable)
info_name = SvPV_nolen (ST (0));
hashtable = weechat_perl_hash_to_hashtable (ST (1),
- WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
result_hashtable = weechat_info_get_hashtable (info_name, hashtable);
result_hash = weechat_perl_hashtable_to_hash (result_hashtable);
@@ -5428,7 +5470,9 @@ XS (XS_weechat_api_hdata_update)
hdata = SvPV_nolen (ST (0));
pointer = SvPV_nolen (ST (1));
hashtable = weechat_perl_hash_to_hashtable (ST (2),
- WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
value = weechat_hdata_update (API_STR2PTR(hdata),
API_STR2PTR(pointer),
@@ -5630,6 +5674,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(string_remove_color);
API_DEF_FUNC(string_is_command_char);
API_DEF_FUNC(string_input_for_buffer);
+ API_DEF_FUNC(string_eval_expression);
API_DEF_FUNC(mkdir_home);
API_DEF_FUNC(mkdir);
API_DEF_FUNC(mkdir_parents);
diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c
index f889aa6be..63ab186bd 100644
--- a/src/plugins/perl/weechat-perl.c
+++ b/src/plugins/perl/weechat-perl.c
@@ -169,14 +169,13 @@ weechat_perl_hashtable_to_hash (struct t_hashtable *hashtable)
/*
* weechat_perl_hash_to_hashtable: get WeeChat hashtable with perl hash
- * Hashtable returned has type string for
- * both keys and values
* Note: hashtable has to be released after use
* with call to weechat_hashtable_free()
*/
struct t_hashtable *
-weechat_perl_hash_to_hashtable (SV *hash, int hashtable_size)
+weechat_perl_hash_to_hashtable (SV *hash, int size, const char *type_keys,
+ const char *type_values)
{
struct t_hashtable *hashtable;
HV *hash2;
@@ -184,9 +183,9 @@ weechat_perl_hash_to_hashtable (SV *hash, int hashtable_size)
char *str_key;
I32 retlen;
- hashtable = weechat_hashtable_new (hashtable_size,
- WEECHAT_HASHTABLE_STRING,
- WEECHAT_HASHTABLE_STRING,
+ hashtable = weechat_hashtable_new (size,
+ type_keys,
+ type_values,
NULL,
NULL);
if (!hashtable)
@@ -198,7 +197,15 @@ weechat_perl_hash_to_hashtable (SV *hash, int hashtable_size)
hv_iterinit (hash2);
while ((value = hv_iternextsv (hash2, &str_key, &retlen)))
{
- weechat_hashtable_set (hashtable, str_key, SvPV (value, PL_na));
+ if (strcmp (type_values, WEECHAT_HASHTABLE_STRING) == 0)
+ weechat_hashtable_set (hashtable, str_key, SvPV (value, PL_na));
+ else if (strcmp (type_values, WEECHAT_HASHTABLE_POINTER) == 0)
+ {
+ weechat_hashtable_set (hashtable, str_key,
+ plugin_script_str2ptr (weechat_perl_plugin,
+ NULL, NULL,
+ SvPV (value, PL_na)));
+ }
}
}
@@ -316,7 +323,9 @@ weechat_perl_exec (struct t_plugin_script *script,
else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE)
{
ret_value = weechat_perl_hash_to_hashtable (POPs,
- WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE);
+ WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING);
}
else
{
diff --git a/src/plugins/perl/weechat-perl.h b/src/plugins/perl/weechat-perl.h
index 87a601aac..5e1eabe48 100644
--- a/src/plugins/perl/weechat-perl.h
+++ b/src/plugins/perl/weechat-perl.h
@@ -35,8 +35,9 @@ extern struct t_plugin_script *perl_registered_script;
extern const char *perl_current_script_filename;
extern HV *weechat_perl_hashtable_to_hash (struct t_hashtable *hashtable);
-extern struct t_hashtable *weechat_perl_hash_to_hashtable (SV *hash,
- int hashtable_size);
+extern struct t_hashtable *weechat_perl_hash_to_hashtable (SV *hash, int size,
+ const char *type_keys,
+ const char *type_values);
extern void *weechat_perl_exec (struct t_plugin_script *script,
int ret_type, const char *function,
const char *format, void **argv);