From: Aamer Akhter Date: 2003-10-02T10:43:30+09:00 Subject: Re: tcltklib and not init'ing tk The following changes appear to work fine. All you need to do (for not starting tk) is to give a non-nil value to the third arg in new: irb(main):003:0> ip1 = TclTkIp.new("bobo",nil,1) tcltklib: Tcl_CreateInterp tcltklib: Tcl_Init tcltklib: tknoload set tcltklib: Tcl_CreateObjCommand("ruby") => # irb(main):004:0> ip1 = TclTkIp.new("bobo",nil,nil) tcltklib: Tcl_CreateInterp tcltklib: Tcl_Init tcltklib: Tk_Init tcltklib: Tcl_StaticPackage("Tk") tcltklib: Tcl_CreateObjCommand("ruby") *** bak/tcltklib.c Wed Oct 1 21:13:43 2003 --- tcltklib.c Wed Oct 1 21:30:28 2003 *************** *** 642,662 **** return Data_Wrap_Struct(self, 0, ip_free, 0); } static VALUE ip_init(argc, argv, self) int argc; VALUE *argv; VALUE self; { struct tcltkip *ptr; /* tcltkip data struct */ ! VALUE argv0, opts; int cnt; /* create object */ Data_Get_Struct(self, struct tcltkip, ptr); ptr = ALLOC(struct tcltkip); DATA_PTR(self) = ptr; ptr->return_value = 0; /* from Tk_Main() */ DUMP1("Tcl_CreateInterp"); --- 642,662 ---- return Data_Wrap_Struct(self, 0, ip_free, 0); } static VALUE ip_init(argc, argv, self) int argc; VALUE *argv; VALUE self; { struct tcltkip *ptr; /* tcltkip data struct */ ! VALUE argv0, opts, tknoload; int cnt; /* create object */ Data_Get_Struct(self, struct tcltkip, ptr); ptr = ALLOC(struct tcltkip); DATA_PTR(self) = ptr; ptr->return_value = 0; /* from Tk_Main() */ DUMP1("Tcl_CreateInterp"); *************** *** 664,711 **** Tcl_Preserve((ClientData)ptr->ip); current_interp = ptr->ip; /* from Tcl_AppInit() */ DUMP1("Tcl_Init"); if (Tcl_Init(ptr->ip) == TCL_ERROR) { rb_raise(rb_eRuntimeError, "%s", ptr->ip->result); } /* set variables */ ! cnt = rb_scan_args(argc, argv, "02", &argv0, &opts); switch(cnt) { case 2: /* options */ ! Tcl_SetVar(ptr->ip, "argv", StringValuePtr(opts), 0); case 1: /* argv0 */ if (argv0 != Qnil) { Tcl_SetVar(ptr->ip, "argv0", StringValuePtr(argv0), 0); } case 0: /* no args */ ; } /* 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 ! /* add ruby command to the interpreter */ #if TCL_MAJOR_VERSION >= 8 DUMP1("Tcl_CreateObjCommand(\"ruby\")"); Tcl_CreateObjCommand(ptr->ip, "ruby", ip_ruby, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); #else DUMP1("Tcl_CreateCommand(\"ruby\")"); Tcl_CreateCommand(ptr->ip, "ruby", ip_ruby, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); #endif --- 664,720 ---- Tcl_Preserve((ClientData)ptr->ip); current_interp = ptr->ip; /* from Tcl_AppInit() */ DUMP1("Tcl_Init"); if (Tcl_Init(ptr->ip) == TCL_ERROR) { rb_raise(rb_eRuntimeError, "%s", ptr->ip->result); } /* set variables */ ! cnt = rb_scan_args(argc, argv, "03", &argv0, &opts, &tknoload); switch(cnt) { + case 3: + /* do we load tk or not */ case 2: /* options */ ! if (opts != Qnil) { ! Tcl_SetVar(ptr->ip, "argv", StringValuePtr(opts), 0); ! } case 1: /* argv0 */ if (argv0 != Qnil) { Tcl_SetVar(ptr->ip, "argv0", StringValuePtr(argv0), 0); } case 0: /* no args */ ; } /* from Tcl_AppInit() */ + if ( tknoload == Qnil ) { 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 ! } else { ! DUMP1("tknoload set"); ! } ! ! /* add ruby command to the interpreter */ #if TCL_MAJOR_VERSION >= 8 DUMP1("Tcl_CreateObjCommand(\"ruby\")"); Tcl_CreateObjCommand(ptr->ip, "ruby", ip_ruby, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); #else DUMP1("Tcl_CreateCommand(\"ruby\")"); Tcl_CreateCommand(ptr->ip, "ruby", ip_ruby, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); #endif How do I go about getting this code reviewed and into ruby proper? I would appreciate any corrections or better ideas for the above. Thanks. Aamer Akhter cisco Systems