0

I want to create an application that is capable of loading plugins. The twist is that I want to be able to create plugins in both C/C++ and Python.

So I've started thinking about this and have a few questions that I'm hoping people can help me with.

My first question is whether I need to use C/C++ for the "core" of the application (the part that actually does the loading of the plugins)? This is my feeling at least, I would think that implementing the core in Python would result in a nasty performance hit, but it would probably simplify loading the plugins dynamically.

Second question is how would I go about defining the plugin interface for C/C++ on one hand and Python on the other? The plugin interface would be rather simple, just a single method that accepts a list of image as a parameter and returns a list of images as a return value. I will probably use the OpenCV image type within the plugins which exists for both C/C++ and Python.

Finally, I would like the application to dynamically discover plugins. So if you place either a .py file or a shared library file (.so/.dll) in this directory, the application would be able to produce a list of available plugins at runtime.

I found something in the Boost library called Boost.Extension (http://boost-extension.redshoelace.com/docs/boost/extension/index.html) but unfortunately it doesn't seem to be a part of the official Boost library and it also seems to be a bit stale now. On top of that, I don't know how well it would work with Python, that is, how easy it would be to create Python plugins that fit into this mechanism.

As a side note, I imagine the application split into two "parts". One part is a stripped down core (loading and invoking plugin instances from a "recipe"). The other part is the core plus a GUI that I plan on writing in Python (using PySide). This GUI will enable the user to define the aforementioned "recipes". This GUI part would require the core to be able to provide a list of available plugins.

Sorry for the long winded "question". I guess I'm hoping for more of a discussion and of course if anybody knows of something similar that would help me I would very much appreciate a pointer. I would also appreciate any concise and to the point reading material about something similar (such as integrating C/C++ and Python etc).

4

1 に答える 1

1

アプリケーションを Python で作成すると、プラグイン用のフォルダーを作成できます。

アプリケーションは、ディレクトリをチェックするか、プラグイン ツリーをトラバースすることにより、それらを検索します。

次に、「インポート」を介してそれらをインポートするか、.so/.dll に ctypes を使用するか、さらに簡単に: boost::python を使用して、通常の python モジュールのように「インポート」できる .so/.dll を作成できます。

C++ を使用せず、Python でスクリプトを作成しようとしないでください。;)

于 2012-11-25T20:47:20.153 に答える