1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 16:53:14 +02:00

Add function "buffer_string_replace_local_var" in script API (patch #7061)

This commit is contained in:
Sebastien Helleu
2010-01-12 10:33:13 +01:00
parent c9b71fca2d
commit 63aaf9dc01
5 changed files with 189 additions and 0 deletions
@@ -5154,6 +5154,46 @@ weechat_ruby_api_buffer_set (VALUE class, VALUE buffer, VALUE property,
RUBY_RETURN_OK;
}
/*
* weechat_ruby_api_buffer_string_replace_local_var: replace local variables ($var) in a string,
* using value of local variables
*/
static VALUE
weechat_ruby_api_buffer_string_replace_local_var (VALUE class, VALUE buffer, VALUE string)
{
char *c_buffer, *c_string, *result;
VALUE return_value;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "buffer_string_replace_local_var");
RUBY_RETURN_ERROR;
}
c_buffer = NULL;
c_string = NULL;
if (NIL_P (buffer) || NIL_P (string))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "buffer_string_replace_local_var");
RUBY_RETURN_ERROR;
}
Check_Type (buffer, T_STRING);
Check_Type (string, T_STRING);
c_buffer = STR2CSTR (buffer);
c_string = STR2CSTR (string);
result = weechat_buffer_string_replace_local_var (script_str2ptr (c_buffer), c_string);
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_current_window: get current window
*/
@@ -7054,6 +7094,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "buffer_get_string", &weechat_ruby_api_buffer_get_string, 2);
rb_define_module_function (ruby_mWeechat, "buffer_get_pointer", &weechat_ruby_api_buffer_get_pointer, 2);
rb_define_module_function (ruby_mWeechat, "buffer_set", &weechat_ruby_api_buffer_set, 3);
rb_define_module_function (ruby_mWeechat, "buffer_string_replace_local_var", &weechat_ruby_api_buffer_string_replace_local_var, 2);
rb_define_module_function (ruby_mWeechat, "current_window", &weechat_ruby_api_current_window, 0);
rb_define_module_function (ruby_mWeechat, "window_get_integer", &weechat_ruby_api_window_get_integer, 2);
rb_define_module_function (ruby_mWeechat, "window_get_string", &weechat_ruby_api_window_get_string, 2);