summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-27 05:38:30 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-27 05:38:30 +0000
commite6480a1f2ac7aca4d49749c6ec980cf30ce79794 (patch)
treef4589f6485af5184595b044869f63fd1a743abe0
parent5691e6ab1fa72b61300ab05dc447981ce764fd31 (diff)
tcltklib#invoke
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/tcltklib/tcltklib.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
index 058fe940425..5f90d25dfed 100644
--- a/ext/tcltklib/tcltklib.c
+++ b/ext/tcltklib/tcltklib.c
@@ -205,6 +205,39 @@ ip_eval(VALUE self, VALUE str)
return(str_new2(ptr->ip->result));
}
+static VALUE
+ip_invoke(int argc, VALUE *argv, VALUE obj)
+{
+ struct tcltkip *ptr; /* tcltkip data struct */
+ int i;
+ Tcl_CmdInfo info;
+ char **av;
+
+ /* get the data struct */
+ Data_Get_Struct(obj, struct tcltkip, ptr);
+
+ av = (char **)ALLOCA_N(char **, argc+1);
+ for (i = 0; i < argc; ++i) {
+ Check_Type(argv[i], T_STRING);
+ av[i] = ALLOCA_N(char, RSTRING(argv[i])->len+1);
+ strcpy(av[i], RSTRING(argv[i])->ptr);
+ }
+ av[argc] = NULL;
+
+ if (!Tcl_GetCommandInfo(ptr->ip, av[0], &info)) {
+ NameError("invalid command name `%s'", av[0]);
+ }
+
+ ptr->return_value = (*info.proc)(info.clientData,
+ ptr->ip, argc, av);
+ if (ptr->return_value == TCL_ERROR) {
+ Fail(ptr->ip->result);
+ }
+
+ /* pass back the result (as string) */
+ return(str_new2(ptr->ip->result));
+}
+
/* get return code from Tcl_Eval() */
static VALUE
ip_retval(VALUE self)
@@ -229,6 +262,7 @@ void Init_tcltklib()
rb_define_singleton_method(ip, "new", ip_new, 0);
rb_define_method(ip, "_eval", ip_eval, 1);
+ rb_define_method(ip, "_invoke", ip_invoke, -1);
rb_define_method(ip, "_return_value", ip_retval, 0);
rb_define_method(ip, "mainloop", lib_mainloop, 0);