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

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

问题描述

我有一个二进制应用程序,它与 Tcl 静态链接,前端是 Tcl 解释器.我想为用户提供使用 Python 执行相同命令的能力,作为关键字选项.Tcl 语法的示例是:

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

所以 python 等价物可能如下所示:

so the python equivalent might look like this:

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

将程序构建两次是否更好,一次作为 Tcl 应用程序,另一次作为 Python 应用程序?或者只是将所有内容保留为 Tcl,并有一个命令可以在其解释器中调用 Python 脚本?

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?

命令的实现方式是它们对所使用的脚本语言一无所知.api是:

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);

Handler 是一个 C++ 类,它处理解析选项并将它们提供给命令实现.到目前为止,处理程序是为 Tcl 实现的,但不是为 Python 实现的.

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.

所有直接与 Tcl 交互的代码都在它自己的目录中,并从程序的其余部分抽象出调用.

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

因为他们在问是从 Tcl 迁移到 Python 还是 Matlab.我已经知道我想同时支持 Tcl 和 Python,而且我非常想知道人们使用了哪些方法.如:

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. 从 Tcl 调用 Python 解释器
  2. 为 Python 前端和 Tcl 前端编译单独的应用程序.
  3. 其他一些方法.

推荐答案

从 Tcl 调用 Python 解释器

Calling a Python interpreter from Tcl

不必要的开销.

然而,Python 的 tkinter 模块从 Python 调用 Tcl.有先例,但引入太多接口层似乎令人费解.

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

为 Python 前端和 Tcl 前端编译单独的应用程序.

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

这很常见.许多项目有多个绑定——Python、Tcl、Perl 等.

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. 修复二进制应用程序以处理简单的文本输入和输出.您将从标准输入读取并写入标准输出.

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

编写收集参数的 Python(和 Tcl)应用程序,将二进制文件分叉为子进程;并将参数写入二进制文件的 stdid 并从二进制文件的标准输出读取结果.

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天全站免登陆