summaryrefslogtreecommitdiff
path: root/src/plugins/scripts/ruby/weechat-ruby-api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/scripts/ruby/weechat-ruby-api.c')
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index c40c2184b..f81be474b 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -5155,6 +5155,46 @@ weechat_ruby_api_buffer_set (VALUE class, VALUE buffer, VALUE property,
}
/*
+ * 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);