mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 09:43:13 +02:00
api: add argument "options" in function string_eval_expression, add option "-c" for command /eval (to evaluate a condition)
This commit is contained in:
@@ -439,15 +439,15 @@ weechat_guile_api_string_input_for_buffer (SCM string)
|
||||
|
||||
SCM
|
||||
weechat_guile_api_string_eval_expression (SCM expr, SCM pointers,
|
||||
SCM extra_vars)
|
||||
SCM extra_vars, SCM options)
|
||||
{
|
||||
char *result;
|
||||
SCM return_value;
|
||||
struct t_hashtable *c_pointers, *c_extra_vars;
|
||||
struct t_hashtable *c_pointers, *c_extra_vars, *c_options;
|
||||
|
||||
API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
|
||||
if (!scm_is_string (expr) || !scm_list_p (pointers)
|
||||
|| !scm_list_p (extra_vars))
|
||||
|| !scm_list_p (extra_vars) || !scm_list_p (options))
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
c_pointers = weechat_guile_alist_to_hashtable (pointers,
|
||||
@@ -458,14 +458,21 @@ weechat_guile_api_string_eval_expression (SCM expr, SCM pointers,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
c_options = weechat_guile_alist_to_hashtable (options,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
|
||||
result = weechat_string_eval_expression (API_SCM_TO_STRING(expr),
|
||||
c_pointers, c_extra_vars);
|
||||
c_pointers, c_extra_vars,
|
||||
c_options);
|
||||
|
||||
if (c_pointers)
|
||||
weechat_hashtable_free (c_pointers);
|
||||
if (c_extra_vars)
|
||||
weechat_hashtable_free (c_extra_vars);
|
||||
if (c_options)
|
||||
weechat_hashtable_free (c_options);
|
||||
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
@@ -4608,7 +4615,7 @@ weechat_guile_api_module_init (void *data)
|
||||
API_DEF_FUNC(string_remove_color, 2);
|
||||
API_DEF_FUNC(string_is_command_char, 1);
|
||||
API_DEF_FUNC(string_input_for_buffer, 1);
|
||||
API_DEF_FUNC(string_eval_expression, 3);
|
||||
API_DEF_FUNC(string_eval_expression, 4);
|
||||
API_DEF_FUNC(mkdir_home, 2);
|
||||
API_DEF_FUNC(mkdir, 2);
|
||||
API_DEF_FUNC(mkdir_parents, 2);
|
||||
|
||||
@@ -159,10 +159,10 @@ IRC_PROTOCOL_CALLBACK(authenticate)
|
||||
IRC_SERVER_OPTION_SASL_MECHANISM);
|
||||
sasl_username = weechat_string_eval_expression (IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_SASL_USERNAME),
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
sasl_password = weechat_string_eval_expression (IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_SASL_PASSWORD),
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
answer = NULL;
|
||||
switch (sasl_mechanism)
|
||||
{
|
||||
@@ -2122,7 +2122,7 @@ IRC_PROTOCOL_CALLBACK(001)
|
||||
/* execute command when connected */
|
||||
server_command = weechat_string_eval_expression (IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_COMMAND),
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
if (server_command && server_command[0])
|
||||
{
|
||||
/* split command on ';' which can be escaped with '\;' */
|
||||
|
||||
@@ -324,10 +324,10 @@ irc_server_sasl_enabled (struct t_irc_server *server)
|
||||
IRC_SERVER_OPTION_SASL_MECHANISM);
|
||||
sasl_username = weechat_string_eval_expression (IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_SASL_USERNAME),
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
sasl_password = weechat_string_eval_expression (IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_SASL_PASSWORD),
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
|
||||
/*
|
||||
* SASL is enabled if using mechanism "external"
|
||||
@@ -3055,7 +3055,7 @@ irc_server_login (struct t_irc_server *server)
|
||||
|
||||
password = weechat_string_eval_expression (IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_PASSWORD),
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
username = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME);
|
||||
realname = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME);
|
||||
capabilities = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_CAPABILITIES);
|
||||
@@ -4154,7 +4154,7 @@ irc_server_autojoin_channels (struct t_irc_server *server)
|
||||
/* auto-join when connecting to server for first time */
|
||||
autojoin = weechat_string_eval_expression (IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_AUTOJOIN),
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL);
|
||||
if (!server->disable_autojoin && autojoin && autojoin[0])
|
||||
irc_command_join_server (server, autojoin, 0, 0);
|
||||
if (autojoin)
|
||||
|
||||
@@ -420,29 +420,36 @@ static int
|
||||
weechat_lua_api_string_eval_expression (lua_State *L)
|
||||
{
|
||||
const char *expr;
|
||||
struct t_hashtable *pointers, *extra_vars;
|
||||
struct t_hashtable *pointers, *extra_vars, *options;
|
||||
char *result;
|
||||
|
||||
API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
|
||||
if (lua_gettop (L) < 3)
|
||||
if (lua_gettop (L) < 4)
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
expr = lua_tostring (L, -3);
|
||||
pointers = weechat_lua_tohashtable (L, -2,
|
||||
expr = lua_tostring (L, -4);
|
||||
pointers = weechat_lua_tohashtable (L, -3,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_POINTER);
|
||||
extra_vars = weechat_lua_tohashtable (L, -1,
|
||||
extra_vars = weechat_lua_tohashtable (L, -2,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
options = weechat_lua_tohashtable (L, -1,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars);
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars,
|
||||
options);
|
||||
|
||||
if (pointers)
|
||||
weechat_hashtable_free (pointers);
|
||||
if (extra_vars)
|
||||
weechat_hashtable_free (extra_vars);
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
@@ -400,11 +400,11 @@ XS (XS_weechat_api_string_input_for_buffer)
|
||||
XS (XS_weechat_api_string_eval_expression)
|
||||
{
|
||||
char *expr, *result;
|
||||
struct t_hashtable *pointers, *extra_vars;
|
||||
struct t_hashtable *pointers, *extra_vars, *options;
|
||||
dXSARGS;
|
||||
|
||||
API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
|
||||
if (items < 3)
|
||||
if (items < 4)
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
expr = SvPV_nolen (ST (0));
|
||||
@@ -416,13 +416,20 @@ XS (XS_weechat_api_string_eval_expression)
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
options = weechat_perl_hash_to_hashtable (ST (3),
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars);
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars,
|
||||
options);
|
||||
|
||||
if (pointers)
|
||||
weechat_hashtable_free (pointers);
|
||||
if (extra_vars)
|
||||
weechat_hashtable_free (extra_vars);
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
@@ -397,14 +397,15 @@ static PyObject *
|
||||
weechat_python_api_string_eval_expression (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *expr, *result;
|
||||
struct t_hashtable *pointers, *extra_vars;
|
||||
PyObject *dict, *dict2, *return_value;
|
||||
struct t_hashtable *pointers, *extra_vars, *options;
|
||||
PyObject *dict, *dict2, *dict3, *return_value;
|
||||
|
||||
API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
|
||||
expr = NULL;
|
||||
pointers = NULL;
|
||||
extra_vars = NULL;
|
||||
if (!PyArg_ParseTuple (args, "sOO", &expr, &dict, &dict2))
|
||||
options = NULL;
|
||||
if (!PyArg_ParseTuple (args, "sOOO", &expr, &dict, &dict2, &dict3))
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
pointers = weechat_python_dict_to_hashtable (dict,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
@@ -414,13 +415,20 @@ weechat_python_api_string_eval_expression (PyObject *self, PyObject *args)
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
options = weechat_python_dict_to_hashtable (dict3,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars);
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars,
|
||||
options);
|
||||
|
||||
if (pointers)
|
||||
weechat_hashtable_free (pointers);
|
||||
if (extra_vars)
|
||||
weechat_hashtable_free (extra_vars);
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
@@ -463,19 +463,22 @@ weechat_ruby_api_string_input_for_buffer (VALUE class, VALUE string)
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_eval_expression (VALUE class, VALUE expr,
|
||||
VALUE pointers, VALUE extra_vars)
|
||||
VALUE pointers, VALUE extra_vars,
|
||||
VALUE options)
|
||||
{
|
||||
char *c_expr, *result;
|
||||
struct t_hashtable *c_pointers, *c_extra_vars;
|
||||
struct t_hashtable *c_pointers, *c_extra_vars, *c_options;
|
||||
VALUE return_value;
|
||||
|
||||
API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
|
||||
if (NIL_P (expr) || NIL_P (pointers) || NIL_P (extra_vars))
|
||||
if (NIL_P (expr) || NIL_P (pointers) || NIL_P (extra_vars)
|
||||
|| NIL_P (options))
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
Check_Type (expr, T_STRING);
|
||||
Check_Type (pointers, T_HASH);
|
||||
Check_Type (extra_vars, T_HASH);
|
||||
Check_Type (options, T_HASH);
|
||||
|
||||
c_expr = StringValuePtr (expr);
|
||||
c_pointers = weechat_ruby_hash_to_hashtable (pointers,
|
||||
@@ -486,13 +489,20 @@ weechat_ruby_api_string_eval_expression (VALUE class, VALUE expr,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
c_options = weechat_ruby_hash_to_hashtable (options,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
|
||||
result = weechat_string_eval_expression (c_expr, c_pointers, c_extra_vars);
|
||||
result = weechat_string_eval_expression (c_expr, c_pointers, c_extra_vars,
|
||||
c_options);
|
||||
|
||||
if (c_pointers)
|
||||
weechat_hashtable_free (c_pointers);
|
||||
if (c_extra_vars)
|
||||
weechat_hashtable_free (c_extra_vars);
|
||||
if (c_options)
|
||||
weechat_hashtable_free (c_options);
|
||||
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
@@ -5945,7 +5955,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
API_DEF_FUNC(string_remove_color, 2);
|
||||
API_DEF_FUNC(string_is_command_char, 1);
|
||||
API_DEF_FUNC(string_input_for_buffer, 1);
|
||||
API_DEF_FUNC(string_eval_expression, 3);
|
||||
API_DEF_FUNC(string_eval_expression, 4);
|
||||
API_DEF_FUNC(mkdir_home, 2);
|
||||
API_DEF_FUNC(mkdir, 2);
|
||||
API_DEF_FUNC(mkdir_parents, 2);
|
||||
|
||||
@@ -735,7 +735,7 @@ script_repo_script_is_held (struct t_script_repo *script)
|
||||
/*
|
||||
* Computes MD5 checksum for the content of a file.
|
||||
*
|
||||
* Note: result has to be freed after use.
|
||||
* Note: result must be freed after use.
|
||||
*/
|
||||
|
||||
char *
|
||||
|
||||
@@ -571,11 +571,11 @@ weechat_tcl_api_string_eval_expression (ClientData clientData,
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *expr, *result;
|
||||
struct t_hashtable *pointers, *extra_vars;
|
||||
struct t_hashtable *pointers, *extra_vars, *options;
|
||||
int i;
|
||||
|
||||
API_FUNC(1, "string_eval_expression", API_RETURN_EMPTY);
|
||||
if (objc < 4)
|
||||
if (objc < 5)
|
||||
API_WRONG_ARGS(API_RETURN_EMPTY);
|
||||
|
||||
expr = Tcl_GetStringFromObj (objv[1], &i);
|
||||
@@ -587,13 +587,20 @@ weechat_tcl_api_string_eval_expression (ClientData clientData,
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
options = weechat_tcl_dict_to_hashtable (interp, objv[4],
|
||||
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING);
|
||||
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars);
|
||||
result = weechat_string_eval_expression (expr, pointers, extra_vars,
|
||||
options);
|
||||
|
||||
if (pointers)
|
||||
weechat_hashtable_free (pointers);
|
||||
if (extra_vars)
|
||||
weechat_hashtable_free (extra_vars);
|
||||
if (options)
|
||||
weechat_hashtable_free (options);
|
||||
|
||||
API_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ struct timeval;
|
||||
* please change the date with current one; for a second change at same
|
||||
* date, increment the 01, otherwise please keep 01.
|
||||
*/
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20130727-01"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20130804-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
@@ -256,7 +256,8 @@ struct t_weechat_plugin
|
||||
const char *(*string_input_for_buffer) (const char *string);
|
||||
char *(*string_eval_expression )(const char *expr,
|
||||
struct t_hashtable *pointers,
|
||||
struct t_hashtable *extra_vars);
|
||||
struct t_hashtable *extra_vars,
|
||||
struct t_hashtable *options);
|
||||
|
||||
/* UTF-8 strings */
|
||||
int (*utf8_has_8bits) (const char *string);
|
||||
@@ -1020,9 +1021,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
#define weechat_string_input_for_buffer(__string) \
|
||||
weechat_plugin->string_input_for_buffer(__string)
|
||||
#define weechat_string_eval_expression(__expr, __pointers, \
|
||||
__extra_vars) \
|
||||
__extra_vars, __options) \
|
||||
weechat_plugin->string_eval_expression(__expr, __pointers, \
|
||||
__extra_vars) \
|
||||
__extra_vars, __options)
|
||||
|
||||
/* UTF-8 strings */
|
||||
#define weechat_utf8_has_8bits(__string) \
|
||||
|
||||
Reference in New Issue
Block a user