Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Using the Tcl Interpreter in my prg
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


Report this thread to moderator Post Follow-up to this message
Old Post
Guenther Sohler
04-22-05 08:58 AM


Re: Using the Tcl Interpreter in my prg
Guenther 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/

Report this thread to moderator Post Follow-up to this message
Old Post
David N. Welton
04-22-05 01:58 PM


Re: Using the Tcl Interpreter in my prg
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 ???



Report this thread to moderator Post Follow-up to this message
Old Post
Guenther Sohler
04-22-05 01:58 PM


Re: Using the Tcl Interpreter in my prg
You 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 ???
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Ron Fox
04-22-05 01:58 PM


Re: Using the Tcl Interpreter in my prg
Guenther 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Donal K. Fellows
04-22-05 09:01 PM


Re: Using the Tcl Interpreter in my prg
According 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/ >

Report this thread to moderator Post Follow-up to this message
Old Post
lvirden@gmail.com
04-22-05 09:01 PM


Re: Using the Tcl Interpreter in my prg
You 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


Report this thread to moderator Post Follow-up to this message
Old Post
Jingzhao Ou
04-23-05 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:24 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.