如何将Python嵌入到C ++ Builder / Delphi 2010应用程序中? [英] How should I embed Python in a C++ Builder / Delphi 2010 application?

查看:288
本文介绍了如何将Python嵌入到C ++ Builder / Delphi 2010应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣在我的应用程序中嵌入Python,让用户在应用程序环境中运行Python脚本,访问内部(C ++ - 实现)对象等。我很新,所以不要知道我在做什么。



我已阅读将Python嵌入到另一个应用程序中,尽管这似乎只涉及C API和平面C函数,而不是类或对象(除非我错过了某些东西)和它的嵌入Python中的C ++部分只有两个句子。不过,我也发现了如何使用boost :: python ,这看起来很好。



有一个问题:boost :: python 不支持C ++ Builder 2010



所以,给定这个,在使用C ++ Builder 2010编译的C ++应用程序中嵌入Python的最佳方法,以及使用哪种最好的技术,您如何暴露/集成类和对象,以使Python编码器能够访问程序的面向对象的内部元素?强>我错过了一个标准的方法?将内部类或实例化对象暴露给Python,因为对象容易,或者API是真正的C风格还是平面/非OO,如果是,通过这种API模拟底层OO层的最佳方法是什么?



注意:我实际上使用RAD Studio,其中包括C ++ Builder和Delphi。可能使用某种Delphi特定的绑定,但是我遇到的是,或者是new-ish(Python 2.6),但似乎没有任何文档,并且在问题列表中发表评论,如任何人都读thiese [sic]评论反正任何人在这个项目工作?这是不令人鼓舞的。但是,如果您认为可能在一个组合的D + CB应用程序中工作,请随时包含Delphi特定的答案。我感谢所有答案,即使他们不完美 - 我可以研究,我只需要指向哪里去。原生C ++解决方案可能是理想的,因为使用VCL派生的对象有其自身的局限性。



感谢您的输入!

解决方案

你不应该害怕在谷歌团队的P4D项目。它似乎是不活跃的,因为它在一定程度上是非常稳定和全功能的。这些组件用于更加活跃的 PyScripter 应用程序,这是最好的python开发编辑器之一目前可用。 PyScripter是用Delphi编写的,它使用P4D组件。因此,它也提供了一个非常全面的如何使用P4D组件的示例,尽管P4D源代码提供的示例已经足够开始了。


I'm interested in experimenting with embedding Python in my application, to let the user run Python scripts within the application environment, accessing internal (C++-implemented) objects, etc. I'm quite new to this so don't know exactly what I'm doing.

I have read Embedding Python in Another Application, though this seems to talk only about a C API and flat C functions, not classes or objects (unless I've missed something) and its "Embedding Python in C++" section is only two sentences long. However, I also came across how to use boost::python and this looks excellent.

There's one problem: boost::python is not supported by C++ Builder 2010.

So, given this, what is the best approach for embedding Python in a C++ application compiled with C++ Builder 2010, and, using whichever technique is best, how do you expose / integrate classes and objects to give the Python coder access to the object-oriented internals of a program? Have I missed a standard approach? Is exposing internal classes or instantiated objects to Python as objects easy, or is the API truly C-style or flat / non-OO, and if so what's the best approach to mimic an underlying OO layer through such an API?

Note: I actually use RAD Studio, which includes both C++ Builder and Delphi. It may be possible to make use of some sort of Delphi-specific binding, but the ones I've encountered are six or seven years old, or are new-ish (Python 2.6) but don't seem to have any documentation and have comments in the issue list like "Anyone reads thiese [sic] comments anyway? Anyone working on this project?" which is not encouraging. But please feel free to include Delphi-specific answers especially if you think it's likely they'll work in a combined D+CB app. I appreciate all answers even if they aren't quite perfect - I can research, I just need pointers on where to go. A native C++ solution would probably be ideal, though, since using VCL-derived objects has its own limitations.

Thanks for your input!

解决方案

You should not be afraid of the P4D project at google groups. It seems inactive because, in part, it is very stable and full-featured already. Those components are used in the much more active PyScripter application which is one of the best python development editors currently available. PyScripter is written in Delphi and uses the P4D components. As such, it also presents a very comprehensive example of how to use the P4D components, although the examples provided with the P4D source checkout are already good enough to get started.

这篇关于如何将Python嵌入到C ++ Builder / Delphi 2010应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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