tcl和python相互通信_同时支持Tcl和Python的?

I have a binary application that is statically linked against Tcl and the front end is the Tcl interpreter. I would like to offer users the capability of using Python to execute the same commands, as keyword options. A sample of the Tcl syntax is:

set_foo -foo 1.0 -bar 3.0 -cat x

so the python equivalent might look like this:

set_foo(foo=1.0, bar=3.0, cat="x")

Is it better to build the program twice, one as a Tcl app, one as a Python app? Or just keep everything as Tcl, and have a command that will invoke a Python script in its interpreter?

The commands are implemented in such a way in that they do not know anything about the scripting language used. The api is:

void set_fooCmd(Handler &data);

and the Handler is a C++ class which handles parsing the options and providing them to the command implementation. So far the Handler is implemented for Tcl, but not Python.

All of the code directly interfacing with Tcl is in its own directory, and abstracts away calls from the rest of the program.

as they are asking whether to move from Tcl to Python or Matlab. I already know I want to support both Tcl and Python, and I would very much like to know what approaches people have used. Such as:

Calling a Python interpreter from Tcl

Compiling separate applications for a Python front end and a Tcl front end.

Some other approach.

解决方案Calling a Python interpreter from Tcl

Needless overhead.

However, Python's tkinter module calls Tcl from Python. There is a precedent, but it seems convoluted to introduce too many interface layers.

Compiling separate applications for a Python front end and a Tcl front end.

This is very common. Many projects have multiple bindings -- Python, Tcl, Perl, etc.

There is one possible way to slightly simplify the language binding.

Fix the binary app to work with simple text input and output. You will read from stdin and write to stdout.

Write Python (and Tcl) applications that gather the parameters, forks the binary as a subprocess; and write the parameters to the binary's stdid and reads results from the binary's stdout.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值