Here is trivial example how to embedd Tcl into your C/C++ program.
Thre are implemented 2 custom commands available from TCL:
-
Command
::ex::uname_machine
that returns machine name from uname(2) system call. -
Command
::ex::uptime_seconds
that returns number of seconds from system start (uptime) from sysinfo(2) system call.
Pleae see also Embedding LUA into C/C++ program for comparison.
WARNING!
Valgrind report lot of leaks but ... the threaded version uses pool of per-thread allocated memory - so it is much harder to interpret results...
Tested OS: Debian9.9 (Stretch)/amd64
Install following required packages:
sudo apt-get install build-essential tcl tcl-dev tcl-doc libtcl8.6-dbg \
git valgrind
Optional: Install Eclipse with CDT (C/C++ development support):
sudo apt-get install eclipse-cdt
TODO: import to Eclipse
Just invoke:
make
To run example just invoke:
make run
Following examples are run:
puts "Hello, world on [::ex::uname_machine]!"
puts "System uptime is [::ex::uptime_seconds] seconds."
should produce output like:
Hello, world on x86_64!
System uptime is 12678 seconds.
To run example with valgrind(1)
memory leak detector use:
make valgrind
NOTE: See notice at the beginning of this readme...
- official Tcl embedding docs:
- nice "Tcl crash course" from OpenOCD author: