同时支持Tcl和Python的? [英] Supporting both Tcl and Python?

查看:619
本文介绍了同时支持Tcl和Python的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是对的Tcl静态链接和前端是TCL间preTER一个二进制应用程序。我想,为用户提供使用Python来执行相同的命令的能力,作为关键字选项。 Tcl的语法的样品是:

  set_foo -foo 1.0 -bar 3.0 -cat点¯x

所以python的等效可能是这样的:

  set_foo(富= 1.0,酒吧= 3.0,猫=X)

它是更好地构建程序两次,一次作为一个Tcl应用程序,一个作为Python应用程序?或者只是把一切都如TCL,并有一个命令,将在其跨preTER调用Python脚本?

该命令在这样的方式,他们不知道所使用的脚本语言实现的东西。 API是:

 无效set_fooCmd(处理器和放大器;数据);

和处理程序是处理解析选项,并把它们提供给命令执行C ++类。到目前为止,处理程序是对Tcl实现的,而不是Python的。

所有code。与Tcl的直接连接的是在自己的目录,并从程序的其他部分抽象了电话。

更新:
这不是一个重复的问题:
<一href=\"http://stackoverflow.com/questions/3167661/picking-a-front-end-inter$p$pter-for-a-scientific-$c$c\">Picking前端/间preTER的科学code。

,因为他们都在问是否从Tcl的移动到Python或Matlab。我已经知道我要支持Tcl和Python和我很想知道人们使用什么样的方法。如:


  1. 从调用Tcl的一个Python间preTER

  2. 编译独立的应用程序为一个Python前端和Tcl的前端。

  3. 其他的一些方法。


解决方案

  

从调用Tcl的一个Python间preTER


不用开销。

然而,Python的 Tkinter的模块从Python中调用的Tcl。有一个precedent,但似乎令人费解引入太多的界面层。


  

编译独立的应用程序为一个Python前端和Tcl的前端。


这是很常见的。许多项目有多个绑定 - 的Python,TCL,Perl等

有是一种可能的方式略微简化语言绑定


  1. 解决二进制应用与简单的文本输入和输出工作。你会从标准输入读取和写入到标准输出。


  2. 编写采集参数,叉二进制作为子进程的Python(和Tcl)的应用;和写入参数二进制的stdid并读取从二进制的标准输出结果。


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.

Update: This is not a duplicate question to: Picking a front-end/interpreter for a scientific code.

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:

  1. Calling a Python interpreter from Tcl
  2. Compiling separate applications for a Python front end and a Tcl front end.
  3. 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.

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

  2. 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.

这篇关于同时支持Tcl和Python的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆