| Nathan West 2006-10-04, 7:02 pm |
|
Dave Dean wrote:
> Hi all,
> I've previously attempted to write a game-type application that consists
> mostly of a bunch of pieces the user can move with a mouse.
> I should mention here that I'm from a hardware background, and not super
> experienced with PC applications.
> My first attempt was purely in C++, using MFC with Visual Studio. I
> managed to make something somewhat functional, but in the end the complexity
> of the whole thing got the better of me, and I grew bored with the project.
> Recently, I've picked up Tcl/Tk, and it seems that the whole Tk toolkit is
> an excellent way to reduce the complexity I was running into (the canvas
> widget automates everything I struggled for w s to figure out). On the
> downside, I still want some of the extra power of C/C++, especially pointers
> and more complicated data structures.
> I'm vaguely familiar with the process of extending Tcl/Tk by writing a
> function in C, and calling it from Tcl. What I'd like is to be able to use
> Tk only as a GUI, and retain all the data structures and computations behind
> the scenes in C. Is there a way to hold all your data in C structures, and
> share that data with the Tk GUI?
>
> One thing I had from Visual Studio was a project using the Document/View
> architecture. If I could implement the View in Tk, but keep the Document in
> C, I think I'd be on track.
>
> I know this is a very broad and somewhat vague question (reflecting my level
> of experience). If anyone can point me in the right direction, either with
> an answer or pointing me towards a particular website or book, I'd
> apprecitate it.
>
> Thanks,
> Dave
Hello,
I am not an expert in Tcl, but I have a similar need to integrate Tcl
and C as simply as possible. I have an embedded system for which I
wrote a GUI to control over a serial line. All of the code in the
embedded system is C and it passes C data structures to and from the
GUI so I cannot avoid C even if I wanted to. When I started the
project I did not even know Tcl existed and I was using Borland C++
Builder 5 to do my GUI.
After a lot of experimenting I found that Borland Builder was very
difficult to use and debug and horribly inefficient, so I started
looking for alternatives and the one thing that drew me to Tcl was the
"easy" integration with C. In fact, the documentation I read (mainly
Pratical Programming in Tcl and Tk) indicated that easy integration
with C was one of the fundamental design goals of Tcl.
Anyway, I started by trying to write pure Tcl to parse the incoming
data into variables, lists and arrays and then manipulate that, but it
quickly became too tiresome. Then I found SWIG and it made my life
very easy. I now have a nicely working system that I think uses the
best of both worlds. I have a single C program that takes care of all
of the data manipulation and whatever else I had a hard time with in
Tcl, a GUI in Tk, and an interface program in TCL to connect the two.
So my advise is to use C for what it is good at, Tcl for what it is
good at and use SWIG to tie them together.
Nathan
|