Code Comments
Programming Forum and web based access to our favorite programming groups.Hallo, I already have a nice prg, but now I want to add some programming capability to it. I decided to use TCL because most stuff is already implemented: if, for, while, most parsing. I only need to add some application specific commands. Then I want to write some tcl functions. The Call stack should be as following * My Prg *Tcl Interpreter * Tcl-Script * for, if .... *Application related callback functions * Tcl Script *Tcl Interpreter * My Prg Very important is, that my prg gains access to the cpu again at the very end. I dont want to launch tclsh in my program, because I wont have access to my data structures anymore, but I need that for the application specific functions. Can anybody give me a starting point(link for a related tutorial) By now I just found tutorials to extend the tclsh interpreter, but my intent is to instanciate a new interpreter without starting a new program. rds
Post Follow-up to this messageGuenther Sohler <guenther.sohler@newlogic.com> writes: > I only need to add some application specific commands. Then I want > to write some tcl functions. The Call stack should be as following > > * My Prg > *Tcl Interpreter > * Tcl-Script > * for, if .... > *Application related callback functions > * Tcl Script > *Tcl Interpreter > * My Prg > Very important is, that my prg gains access to the cpu again at the > very end. I dont want to launch tclsh in my program, because I wont > have access to my data structures anymore, but I need that for the > application specific functions. Tcl is perfect for this. > Can anybody give me a starting point(link for a related tutorial) By > now I just found tutorials to extend the tclsh interpreter, but my > intent is to instanciate a new interpreter without starting a new > program. If you want to dig around in some source code, the 'Apache Rivet' system does exactly what you are doing. It's perhaps a little bit more complex that might be desireable to start out with, but you'll find it covers a decent portion of the Tcl C API, and it's available under a liberal license. -- David N. Welton - http://www.dedasys.com/davidw/ Apache, Linux, Tcl Consulting - http://www.dedasys.com/
Post Follow-up to this messageHallo,
thank you for your suggestion.
Now I was able to write a nice small c program executing tcl!
#include<stdio.h>
#include<tcl.h>
int main(int argc,char *argv[])
{
Tcl_Interp *interp;
interp=Tcl_CreateInterp();
Tcl_Init(interp);
Tcl_EvalFile(interp,"test.tcl");
Tcl_DeleteInterp(interp);
return 0;
}
I somehow need to define some callback functions - registering functions.
but i did not find any apropriate function in the tcl header files.
Any hints ???
Post Follow-up to this messageYou should probably get and read the Welch book or even the Ousterhout
book as these describe the Tcl API unless you are very good at learning
from man pages... you could start also by looking at the man page for:
tcl_createobjcommand
as the trail of breadcrumbs starts there.
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321
In his novel ''Dog Years,'' Gunter Grass parodies Heideggerese in the
character of a German Air Force auxiliary named Stortebeker, who
''created a philosophical schoolboy language that was soon prattled by
many, with varying success.'' Every commonplace incident or object can
be rechristened in Stortebeker/Heidegger's hilarious language. Underdone
potatoes in the mess kitchen, for example, are ''spuds forgetful of
Being.'' Stortebeker relaxes by catching rats, so they are the object of
some of his best ruminations: ''The rat withdraws itself by unconcealing
itself into the ratty. So the rat errates the ratty, illuminating it
with errancy. For the ratty has come-to-be in the errancy where the rat
errs and so fosters error.''
Guenther Sohler wrote:
> Hallo,
>
> thank you for your suggestion.
> Now I was able to write a nice small c program executing tcl!
>
>
>
> #include<stdio.h>
> #include<tcl.h>
>
> int main(int argc,char *argv[])
> {
> Tcl_Interp *interp;
> interp=Tcl_CreateInterp();
> Tcl_Init(interp);
> Tcl_EvalFile(interp,"test.tcl");
> Tcl_DeleteInterp(interp);
> return 0;
> }
>
> I somehow need to define some callback functions - registering functions.
> but i did not find any apropriate function in the tcl header files.
> Any hints ???
>
>
Post Follow-up to this messageGuenther Sohler wrote:
> I somehow need to define some callback functions - registering functions.
> but i did not find any apropriate function in the tcl header files.
> Any hints ???
Well, for simple stuff like you're doing, it is perhaps better to do
this (written from memory):
#include "tcl.h"
int main(int argc, char **argv) {
Tcl_Main(argc, argv, &LocalInit);
return 0;
}
int LocalInit(Tcl_Interp *interp) {
Tcl_SetVar(interp, "example", "value", TCL_GLOBAL_ONLY);
/*
* Also Tcl_CreateCommand, Tcl_LinkVar, Tcl_EvalFile, etc.
*/
return TCL_OK;
}
If you're doing something more complex (i.e. not using Tcl_Main) it is
strongly recommended that you call Tcl_FindExecutable(argv[0]) *first*
before doing the sorts of thing that you wrote. And the correct spot to
put your extra stuff in that case is immediately after the call to
Tcl_CreateInterp...
Donal.
Post Follow-up to this messageAccording to Guenther Sohler <guenther.sohler@newlogic.com>: :Can anybody give me a starting point(link for a related tutorial) :By now I just found tutorials to extend the tclsh interpreter, :but my intent is to instanciate a new interpreter without starting a new :program. Check http://wiki.tcl.tk/3474 (not a tutorial as such but at least some pointers). Check around the rest of the wiki for more information. -- <URL: http://wiki.tcl.tk/ > MP3 ID tag repair < http://www.fixtunes.com/?C=17038[/<...rg/NET/lvirden/ >
Post Follow-up to this messageYou may want to check out the Jim interpreter, which is an opensource small footprint implementation of the Tcl programming language. Should be very easy to make it work with your specific application. http://jim.berlios.de/ Best regards, Jingzhao
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.