From 63aaf9dc01fef850ba5a00d11073c9d8a17b3b82 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 12 Jan 2010 10:33:13 +0100 Subject: Add function "buffer_string_replace_local_var" in script API (patch #7061) --- src/plugins/scripts/tcl/weechat-tcl-api.c | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/plugins/scripts/tcl/weechat-tcl-api.c') diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index 6e7e1a53a..2e3553256 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -4777,6 +4777,42 @@ weechat_tcl_api_buffer_set (ClientData clientData, Tcl_Interp *interp, TCL_RETURN_OK; } +/* + * weechat_tcl_api_buffer_string_replace_local_var: replace local variables ($var) in a string, + * using value of local variables + */ + +static int +weechat_tcl_api_buffer_string_replace_local_var (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj *objp; + char *buffer, *string, *result; + int i; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "buffer_string_replace_local_var"); + TCL_RETURN_ERROR; + } + + if (objc < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "buffer_string_replace_local_var"); + TCL_RETURN_ERROR; + } + + buffer = Tcl_GetStringFromObj (objv[1], &i); + string = Tcl_GetStringFromObj (objv[2], &i); + + result = weechat_buffer_string_replace_local_var (script_str2ptr (buffer), string); + + TCL_RETURN_STRING_FREE(result); +} + /* * weechat_tcl_api_current_window: get current window */ @@ -6683,6 +6719,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) weechat_tcl_api_buffer_get_pointer, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::buffer_set", weechat_tcl_api_buffer_set, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp, "weechat::buffer_string_replace_local_var", + weechat_tcl_api_buffer_string_replace_local_var, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::current_window", weechat_tcl_api_current_window, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp, "weechat::window_get_integer", -- cgit v1.2.3