1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
void UlisBoost::LaunchScript(char * fctName)
{
using namespace std;
PyObject *pName, *pModule, *pDict, *pFunc;
// Initialize the Python Interpreter
Py_Initialize();
// Build the name object
pName = PyString_FromString("scriptBoost");
if(pName == NULL)
{
cout<< "error" << endl;
}
// Load the module object
pModule = PyImport_Import(pName);
if(pName == NULL)
{
cout<< "pModule" << endl;
}
// pDict is a borrowed reference
pDict = PyModule_GetDict(pModule);
if(pDict == NULL)
{
cout<< "erreur du Dico" << endl;
}
// pFunc is also a borrowed reference
pFunc = PyDict_GetItemString(pDict, fctName);
if(pFunc == NULL)
{
cout<< "erreur fonction test" << endl;
}
if (PyCallable_Check(pFunc))
{
cout << "******** Lancement de la fonction Python ********" << endl;
PyObject_CallFunction(pFunc, NULL);
}
else
PyErr_Print();
// Clean up
Py_DECREF(pModule);
Py_DECREF(pName);
// Finalize the Python Interpreter
Py_Finalize();
cout << "******** Fin du script Python ********" << endl;
} |
Partager