From: Aamer Akhter Date: 2003-10-02T05:02:23+09:00 Subject: Re: tcltklib and not init'ing tk Nice to see a fellow industry member dealing with the same problem ;-) On 10/1/03 10:06 AM, in article 20031001140652.GA29212@vor-lord.ftc.agilent.com, "Brett H. Williams" wrote: > On Oct 1, Aamer Akhter wrote: >> Hello, >> >> I'm using the tcltklib extension in ruby 1.8. It seems to be working >> well for my transition from tcl. There are a couple of stumbling >> blocks I'm running into: >> >> 1) is there a way to _not_ start tk? When I create a new interpreter >> (let's say from a non X-fwded ssh session) it may cause a failure. I'm >> only interested in Tcl. > > This is a big pain for me as well. I would really like to have this fixed, > as Ruby/Tcl interaction is important to me. But it hasn't been a big > enough pain to try and hack around in the C code :) (yet) I'm more than willing to spend some time on this. But I'm new to ruby, and to the tcl-C portions. It seems like the thing to do is be able to pass the desire for no tk in via the new call: TclTkIp.new(notk => 1), It looks like tcltklib.c:ip_init() gets called. The current parameters wind up being plugged into Tcl's argv0 and args. So, in keeping with the current implementation perhaps something like: TclTkIp.new($argv0, $args, 1) would be "better" Where 1 represents the non-desire to load Tk. One would need to skip over when 1 is set.: /* from Tcl_AppInit() */ DUMP1("Tk_Init"); if (Tk_Init(ptr->ip) == TCL_ERROR) { rb_raise(rb_eRuntimeError, "%s", ptr->ip->result); } DUMP1("Tcl_StaticPackage(\"Tk\")"); #if TCL_MAJOR_VERSION >= 8 Tcl_StaticPackage(ptr->ip, "Tk", Tk_Init, Tk_SafeInit); #else Tcl_StaticPackage(ptr->ip, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL); #endif >> 2) Is there a japanese to english translation of >> ext/tcltklib/MANUAL.euc? Or can somebody point to a tool that I may >> use to do the translation? babelfish.altavista does not appear to >> work. > > I've done all of my work without any kind of documentation in English. > There just doesn't seem to be that strong an interest in mixing Ruby and > Tcl (we are some of the exceptions). The tcltklib extension was written > for Ruby/Tk. Access to the Tcl interpreter through it is a side effect--a > highly useful side effect for me and you, but nevertheless not really > what was intended by the developers. So using the Tcl interpreter from > Ruby, and vice versa, is probably not even well documented in Japanese > (someone please correct me if I am wrong). > >> 3). Are there any examples of ruby methods being called from the tcl >> code running inside the interpreter? > > This is how I do it: > > set somevar [ruby "some_method()"] > > You can put any ruby code as the argument to the 'ruby' proc. You _must_, > however, make sure that the return value of the ruby code is a string, or > things will crash. ;-) yeah. I already ran into that. I've been using the ruby_fmt proc that tcltk creates on init. That's just a wrapper for calling the ruby tcl command. > > You likely will have to do some creative things to get the scope that you > want--Tcl can only communicate directly with class or global variables. > This means if you call out to Tcl from Ruby, you will not have access to > instance or local variables. It makes perfect sense, but typically > requires doing some non-rubyish things to get access to what you need in > Tcl. I don't think the importance of the above has sunk in yet. Do you mean to say that in a class, I won't be able to do something like: Ip._eval("puts #{var}")