Embedded Systems Page. Tutorial - Controlling The Real World With Computers. An embeddable C/C++ interpreter. Tcl/Tk - Using Tcl from C. Exercises, examples and other material relating to training module T243.
This topic is presented on public courses Learning to program in Tcl, Tcl Basics The majority of Tcl users will use the Tcl shell itself, or wish or expect or another application in which the language is already embedded. If you want to embed Tcl in an application yourself, this module gives you a brief introduction. Examples from our training material Pictures We will teach Tcl wherever required Background information Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from Topics covered in this module Embedding a Tcl interpreter in C Program.Hello Integrated World.Hiding Tcl source code from the user.Extending Tcl - adding a command written in C.
Complete learning If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page. TIP #66: Stand-alone and Embedded Tcl/Tk Applications. Abstract This TIP describes the development and deployment of Tcl/Tk applications, with particular attention on how to embed the interpreter into executables written in C or C++. Introduction and Background Usually, an application that uses Tcl/Tk in some way uses an independent installation and the application itself is started via a standard shell, like tclsh or wish. There are numerous occasions when such a set-up is not convenient: Another reason to document the resources used by Tcl/Tk is that this provides better insight in how to tune Tcl/Tk for a particular application. Two examples may illustrate the need for such stand-alone applications and what is involved: When we were building an installation script for an MS Windows application using one of the commercial tools that are available for this arcane job, we ran into a bizarre limitation: text replacement was possible for the so-called Windows INI-files only, but not for other types of files.
Related TIPs and Discussions. An Example for Embedding Tcl. Tcl crypt -- An Example for Embedding Tcl Download example as gzipped tar file.
When Tcl/Tk was new to me, I missed a small, but complete and working example on how to integrate C functions into Tcl and Tk. John Ousterhout's book on Tcl and Tk describes the C and Tcl parts of the task well, but does not show how to put a working interpreter together. This example makes the Unix crypt(3) function available as a Tcl command. It shows how to write a C function that can be called from Tcl, how to integrate it into the Tcl interpreter (wish, in this case), how to build the interpreter executable, and how to use the newly created command from Tcl.
In commenting this example, I assume that you are familiar with the appropriate chapters of John Ousterhout's book. The Tcl command is named "crypt". The C function is contained in the file tcl_crypt.c, which is shown below. tcl_crypt.c Tcl_Crypt first checks its argc. TkAppInit.c-patch tcl_crypt.h int Crypt_Init(Tcl_Interp *interp) ; Makefile #!