| C++/Tcl A C++ library for interoperability between C++ and Tcl |
// example1.cc
#include "cpptcl.h"#include <iostream>using namespace std;void hello(){ cout << "Hello C++/Tcl!" <<
endl;}CPPTCL_MODULE(Mymodule, i){ i.def("hello", hello);}mymodule.so), we can do this:$ tclsh% load ./mymodule.so% helloHello C++/Tcl!% for {set i 0} {$i != 4} {incr i} { hello }
Hello C++/Tcl!
Hello C++/Tcl!
Hello C++/Tcl!
Hello C++/Tcl!
% // example2.cc
#include "cpptcl.h"
#include <iostream>
#include <string>
using namespace std;
using namespace Tcl;
void hello()
{
cout << "Hello C++/Tcl!" << endl;
}
int main()
{
interpreter i;
i.def("hello", hello);
string script = "for {set i 0} {$i != 4} {incr
i} { hello }";
i.eval(script);
}
$ ./example2
Hello C++/Tcl!
Hello C++/Tcl!
Hello C++/Tcl!
Hello C++/Tcl!
$