-IV- Other than C, what languages can talk to tcl/tk?

From: FAQ General information


A. Shell

	There are a number of interfaces which are shell-like.  The
first is tclsh, which comes as a sample program implementing a Tcl
interpreter as a part of the Tcl distribution.  Another is wish, which
is a shell-like interface that is a part of the Tk package.  Many of
the other extensions also build interpreters as well.  The tclX extension
is an example - it builds an interpreter called tcl as well as one called
wishx.


B. C++

	There is a package called Objectify which can be used to assist
one in turning C++ classes into Tcl object types.

	If you wish to use C++ with Tcl then you must have your main()
in a source file that is compiled with a C++ compiler; this will
ensure that the necessary C++ pre-main initialization code is
executed.

	You can call tcl and tk routines (or other C code) routines from C++
provided that the function prototypes avoid C++ name mangling by using
the C++ linkage specification :

    extern "C"  ... prototype ...

	Fortunately, tcl.h and tk.h will provide these specifications when
compiled with a C++ compiler and so you can just use them directly.

	You can construct your main using normal tcl and tk routines,
or use tkMain.c and tkAppInit.c with minor modifications. Ken Yap's
patch, obtainable from
<URL:ftp://ftp.aud.alcatel.com/tcl/distrib/tk3.2forC++.patch, is a
patch that allows tk 3.2 main.c and other extension routines to be
compiled with a C++ compiler.  Thanks to Ken Yap
<URL:mailto:ken@syd.dit.csiro.au> for this code.

	C++ functions and static class member functions can be used to
create Tcl command using Tcl_CreateCommand in the normal way.
Non-static member functions cannot be used so simply, Tcl would
have to supply a "this" pointer.

	Check out tcl++.h in Extended Tcl.  Based on an original
implementation by Parag Patel, it defines a Tcl interpreter class by
which Tcl interpreters can be created as objects under C++.

	Mark Diekhans and Karl Lehenbauer have used this, in
combination with the handle facility in Extended Tcl, to build Tcl
commands around C++ classes.

	The Tcl handle facility provides a way to manage table entries
that can be referenced by a textual handle from Tcl code.  This is
provided for applications that need to create data structures in one
command, return a reference (i.e. pointer) to that particular data
structure and then access that data structure in other commands.  An
example application is file handles.

	A handle table was built containing pointers to the instances
of a class that were to be accessed from Tcl, say a class `foo_cl', and
then a "new" command defined that created an instance of that class and
returned a Tcl handle to it.  The handle could then passed among Tcl
commands that accessed each member function.  The handle is in effect
an explicit `this' pointer.

	For example:

     set obj [foo_cl::new]
     foo_cl::baz $obj "Hello world"
     foo_cl::delete $obj

It's not totally object-oriented, but it's still very usable.


C. Modula-3

	Norman Ramsey <URL:mailto:elan.uucp!nr> says:
	A long time back, Eric Muller posted a Modula-3 interface to
the C Tcl library.  I wrote down a Modula-3/Tcl interface that used
Modula-3 types rather than C types, and that used objects to build
closures for commands.  I wrote part of the implementation but never
finished it.  I have mailed copies to <URL:mailto:carroll@udel.edu>,
who asked the question, and I will post them if there seems to be general
interest.

	Also, there is an interface between Tk and Modula-3 that is a part
of the Modula-3 archives on gatekeeper.dec.com, and Tcl-DP and
Modula-3 have been merged.


D. Eiffel

	<URL:mailto:stephan@cs.tu-berlin.de> (Stephan Herrmann) says:
	... [the tclish package provides] the marriage of two very different
principles by means of combining two programming languages into a
hybrid program architecture.

	There are three classes for the user - tcl interpretor, tk application,
and tk window.  See <URL:ftp://hepunx.rl.ac.uk/pub/eiffel/tclish for
details.


E. Ada

	<URL:mailto:dennis@dennis.cs.colorado.edu> (Dennis Heimbigner)
introduced an adatcl package which gives Ada programmers access to Tcl
interpreters.  (See tcl-faq/part4) for details of the package.

F. Perl

	Two different projects are underway - see comp.lang.perl
for discussions on adding a Tk like interface to Perl version 4 as well
as Perl version 5.  This is more an interface based on Tk ideas
than to actual Tcl code from what I understand.

G. Prolog

	The package ProTcl is an interface between Prolog and Tcl/Tk.
It works best with ECLiPSe, but the foreign interface of SICStus and Quintus
is also provided. The interface is dynamically loaded into a Prolog process
and it gives access to Tcl commands and to handling Tk events. It is also
possible to call Prolog from Tcl, handle Tk events in Prolog and to
pass Prolog variables back to Tcl. See
<URL:http://www.ecrc.de/eclipse/html/protcl.html for more details.

H. Other

	Work at consolidating Python and Tk is underway - discussion
is proceeding in comp.lang.python on this front as the code is primarily
Python.

	Some work relating to the Fresco CORBA interpreter has resulted in a
Tcl-based interpreter which interacts with that environment.

	Some work on Tk bindings for the Dylan language are being investigated
as well as Tk bindings for Sather.

	Duncan Sinclair <URL:mailto:sinclair@dcs.gla.ac.uk> has details of a 
hack into wish.c some hooks for a Tk <-> any language system, and has been 
using it for communication with functional languages such as Haskell and 
Lazy ML.  A paper, plus sample code, is available by ftp from
<URL:ftp://ftp.dcs.gla.ac.uk/pub/glasgow-fp/authors/Duncan_Sinclair/fumx.*.

	The InterLanguage Unification project is a system that promotes
software interoperability via interfaces.  It has the ability to allow
Common Lisp, ANSI C, C++, Modula 3 to interact and plans to add Python,
Tcl, and GNU Emacs-Lisp shortly.

	Of course the Wafe application environment is designed to make
it easier to do X like applications from within several languages using
Tk as a basis.

	There are several interfaces to allow one to interface with SQL
though some are specific to a database such as Oracle.

	There is an interpretor for Silicon Graphics machines for SGI's
GL language.

	There is an interface to WOOL.

	For more details on the above efforts, (See tcl-faq/part4).

Parent document is top of "comp.lang.tcl Frequently Asked Questions (August 31, 1995) (1/5)"
Previous document is "-III- Do these packages run on my machine?"
Next document is "-V- What training material is available?"