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

Tcl as a configuration language?

21 views
Skip to first unread message

koffee

unread,
Oct 11, 2007, 4:48:10 PM10/11/07
to
Hi,

I'm wondering if Tcl can act as a configuration language for another
application written in C?

I have an application which needs some user-specified data
(parameters, arrays, etc.). What I can do is to configure this
parameters in the source codes and recompile them everytime I change
one of the parameters.

So I'm thinking of using Tcl as a configuration language, writing
every parameters in a script, and let my application READ the data
from the script.

I know ns-2 (Network Simulator 2) is implemented in this way. But it
depends on Otcl and TclCL (which I'm not familiar with).

I wonder if the standard Tcl C library provides this kind of
interface? Or anyone could instruct me to some tutorials or books
about it?

Thanks in advance!

suchenwi

unread,
Oct 11, 2007, 4:54:00 PM10/11/07
to
koffee schrieb:

> I'm wondering if Tcl can act as a configuration language for another
> application written in C?

That's what it was designed for in the beginning :^)


>
> I have an application which needs some user-specified data
> (parameters, arrays, etc.). What I can do is to configure this
> parameters in the source codes and recompile them everytime I change
> one of the parameters.
>
> So I'm thinking of using Tcl as a configuration language, writing
> every parameters in a script, and let my application READ the data
> from the script.
>
> I know ns-2 (Network Simulator 2) is implemented in this way. But it
> depends on Otcl and TclCL (which I'm not familiar with).
>
> I wonder if the standard Tcl C library provides this kind of
> interface?

Sure. With a call to
Tcl_LinkVar(interp, varName, addr, type)
you can link global C variables to Tcl ones, let your users write in a
script
set foo 42
set bar whatever
...
and retrieve those setting from your C/C++ program.

Cameron Laird

unread,
Oct 11, 2007, 8:20:18 PM10/11/07
to
In article <1192135690.5...@y42g2000hsy.googlegroups.com>,

koffee <luk...@gmail.com> wrote:
>Hi,
>
>I'm wondering if Tcl can act as a configuration language for another
>application written in C?
.
.
.
These people <URL: http://www.unixreview.com/documents/s=10083/ur0605k/ >
sure seem to think so. Also <URL:
http://groups.google.com/group/comp.lang.tcl/msg/ba50eb111752812b >.

Ron Fox

unread,
Oct 12, 2007, 5:26:33 AM10/12/07
to
Users of the data acquisition system at the National Superconducting
Cyclotron Lab at Michigan State university use Tcl as a configuration
language for their experiment specific Readout software all the time.
That software is written in C/C++. Normally they use Tcl to set a bunch
of configuration variables and then use Tcl_GetVar and TclGetVar2 to
fetch those values out.
If dynamically modifiable configuration is required (things that can
change during a run of a data taking or
analysis program), they'll either link variables to C/C++
variables/class variables, or define application specific commands that
extend the interpreter, so that action at the C/C++ level is taken
in response to an interaction with the software.
On a side note it's also not unusual for the experimenters to use
Tcl as a configuration language for Tcl scripts.
Tutorials...well I used to be able to say that the Ousterhout book
was the best book for teaching you how to interact with the interpreter.
It's out of date, however since Tcl 8.4 and later. The Welch book is
ok but less tutorial in that regard, and more a reference. The man
pages are fine but suffer from the same problem all manpages have, you
sort of need to know what to look for in order to find what you need to
know.
Tcl2008 organizers.. how about a tutorial session on the Tcl API?
Ron.

Cameron Laird

unread,
Oct 12, 2007, 6:36:38 AM10/12/07
to
In article <fenek9$4vl$1...@aioe.org>, Ron Fox <f...@nscl.msu.edu> wrote:
>Users of the data acquisition system at the National Superconducting
>Cyclotron Lab at Michigan State university use Tcl as a configuration
>language for their experiment specific Readout software all the time.
.
.

.
> Tutorials...well I used to be able to say that the Ousterhout book
>was the best book for teaching you how to interact with the interpreter.
>It's out of date, however since Tcl 8.4 and later. The Welch book is
>ok but less tutorial in that regard, and more a reference. The man
>pages are fine but suffer from the same problem all manpages have, you
>sort of need to know what to look for in order to find what you need to
>know.
> Tcl2008 organizers.. how about a tutorial session on the Tcl API?
.
.
.
There are important tutorial offerings beyond those Ron mentions
above:
A. <URL: http://www.unixreview.com/documents/s=8887/ur0309l/ >
describes a book which is more current than Brent's, in some
regards, and better suited to newcomers;
B. The author of that same book also has supported for a dozen
years <URL: http://ghq.tcl.tk/announce?k=29d593 > TclTutor
<URL: http://wiki.tcl.tk/tcltutor >;
C. <URL: http://wiki.tcl.tk/tutorial >.

tom.rmadilo

unread,
Oct 13, 2007, 12:44:24 AM10/13/07
to
On Oct 11, 1:48 pm, koffee <luke...@gmail.com> wrote:
> Hi,
>
> I'm wondering if Tcl can act as a configuration language for another
> application written in C?
>
> I have an application which needs some user-specified data
> (parameters, arrays, etc.). What I can do is to configure this
> parameters in the source codes and recompile them everytime I change
> one of the parameters.

The Tcl C API is great for more than this, you could use it for
managing most of your application. It is very common to write a
library in C and then connect up the C API, including the data
structures, to Tcl scripting. Tcl C API can provide many advanced
features that usually have to be figured out in any application, one
of which is configuration.

Maybe the primary source for doing this would be the Tcl source code.
Every Tcl command is implemented in C, including list and array
creation. The only difference in your case is that you pass the data
in via a script and then use is mostly in C.

0 new messages