There are several events in my application, each event can have some actions. These actions are implemented in C ++. I want to show these basic functions in python and use python to write an action. The advantage is that I can change actions without recompiling. For instance:
CppClass o; // --- this is a action---- o.f1(); o.f2(); // ------------------------
use python for script action:
def action1(o): o.f1() o.f2()
In C ++, use an interpreter to run this script, find action1 and call it with PyObject, which converts from a C ++ object. In fact, I do not disclose f1 () and f2 () in python, I just use python to rearrange the definition of the action, the whole function is executed by C ++ binary code. Note that I should not give a definition of f1 () and f2 () in python.
The problem is this: how do I expose global functions? eg:
def action2(): gf1() gf2()
boost :: python can expose a function, but it is different, it needs to compile a DLL file, and main () belongs to a python script. Of course, I can make global functions a static member of the class, but I just want to know. Note that I have to give the definition of gf1 () and gf2 () in python.
Jython can do this easily: just import Xxx into python code and call Xxx.gf1 () in order. But in cython, how do I define gf1 () in python? This is a kind of extension, but the extension requires that Xxx be compiled in advance. It seems the only way is to make gf () into a class?
source share