How to extend TCL with C++?

喜你入骨 提交于 2019-12-12 19:57:23

问题


Can I write a C++ code that can be compiled and used for extending TCL (I don't mean calling an executable file)? Can I describe some classes, functions and use them for in my TCl code by calling the compiled (.so or .a file) C++ code? If yes, then please explain me schematically how it is being done.


回答1:


http://cpptcl.sourceforge.net/ It is a C++ wrapper of Tcl C API and very convenient to use, well documented. I tell this from my personal experience.

C++/Tcl is a library that allows to easily integrate C++ and Tcl. If you write programs in both languages, you will find it to be extremely helpful.

The C++/Tcl library was inspired by the Boost.Python library and was designed to provide a similar interface.

Currently, the C++/Tcl library offers the following features: Support for both extending Tcl with C++ modules and embedding Tcl in C++ applications. Possibility to expose free C++ functions as commands in Tcl. Possibility to define classes and class member functions, visible in Tcl in the style similar to SWIG wrappers. Possibility to manipulate Tcl lists and objects from the C++ code.




回答2:


You can extend TCL with C++. Especially have a look at the Itcl++ tool.




回答3:


Have a look at this question, it shows how to create an Tcl extension using Visual C++ under Windows. The process under Unix is similar but you create a Unix .so library rather than a .dll.




回答4:


You might consider using SWIG to build the binding. It doesn't produce a particularly idiomatic Tcl interface (Tcl and C++ being rather different languages after all) but it does allow you to get working very rapidly.



来源:https://stackoverflow.com/questions/5063490/how-to-extend-tcl-with-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!