Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to convert Tcl extension into core command for TIP

50 views
Skip to first unread message

Kevin Walzer

unread,
Mar 4, 2018, 11:01:09 PM3/4/18
to
I'm working on developing an implementation for a TIP that I plan to
propose, based on a Tcl extension package I wrote some years ago. Most
of the functionality is already implemented, but I'm not sure how to
translate some of the extension bits into a core command.

The area that is giving me some difficulty is how to refactor the
package initialization code. A lot of the functionality of the module is
dependent on getting a handle for the main Tcl interpreter. See below:

//initalize the package in the tcl interpreter, create tcl commands
int Tclservices_Init (Tcl_Interp *interp) {

//set up an autorelease pool
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
return TCL_ERROR;
}
if (Tk_InitStubs(interp, "8.5", 0) == NULL) {
return TCL_ERROR;
}


Tcl_CreateObjCommand(interp, "::tclservices::registerservicewidget",
RegisterServiceWidget,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);


//initialize instance of TclServices to provide service functionality
TclService *service = [[TclService alloc] init];
myInterp = interp;
[NSApp setServicesProvider:service];


if (Tcl_PkgProvide(interp, "tclservices", "1.0") != TCL_OK) {
return TCL_ERROR;
}

[pool release];

return TCL_OK;

}

Where in Tk's codebase can I add some of these initialization bits to
ensure that I have a handle on the correct interpreter, create the key
command, and so on? None of the core files use this initialization
routine, of course, but it must be done somewhere. Advice is appreciated.

Thanks,
Kevin


--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com

Kevin Kenny

unread,
Mar 4, 2018, 11:25:34 PM3/4/18
to
On Sunday, March 4, 2018 at 11:01:09 PM UTC-5, kw wrote:
> Where in Tk's codebase can I add some of these initialization bits to
> ensure that I have a handle on the correct interpreter, create the key
> command, and so on? None of the core files use this initialization
> routine, of course, but it must be done somewhere. Advice is appreciated.

Are you looking for the Initialize() function in generic/tkWindow.c ?
That's where Tk installs itself into the interpreter.

Christian Gollwitzer

unread,
Mar 5, 2018, 3:01:07 AM3/5/18
to
Am 05.03.18 um 04:52 schrieb Kevin Walzer:
> I'm working on developing an implementation for a TIP that I plan to
> propose, based on a Tcl extension package I wrote some years ago.  Most
> of the functionality is already implemented, but I'm not sure how to
> translate some of the extension bits into a core command.
>
> The area that is giving me some difficulty is how to refactor the
> package initialization code. A lot of the functionality of the module is
> dependent on getting a handle for the main Tcl interpreter. See below:
>
> //initalize the package in the tcl interpreter, create tcl commands
> int Tclservices_Init (Tcl_Interp *interp) { ....

well, have a look into other "submodules", how they are initialized. For
example, in tclZlib.c in line 3880, you have such an init function
called TclZlibInit. In tclBasic.c line 981, function Tcl_CreateInterp,
it is called when the interpreter is created. I suggest adding it
somewhere here. A little bit further up in this function you'll see many
other init functinos called up like:

TclInitArrayCmd(interp);
TclInitBinaryCmd(interp);
TclInitChanCmd(interp);
TclInitDictCmd(interp);

...and so forth.

Christian
0 new messages