| 9 | { |
| 10 | |
| 11 | BluePy CreateInstance( const char* moduleName, const char* className ) |
| 12 | { |
| 13 | BluePy actionName( PyList_New( 1 ) ); |
| 14 | PyList_SET_ITEM( actionName.o, 0, PyUnicode_FromString( className ) ); |
| 15 | |
| 16 | BluePy module( PyImport_ImportModuleLevel( (char*)moduleName, nullptr, nullptr, actionName, 0 ) ); |
| 17 | if( !module ) |
| 18 | { |
| 19 | CCP_LOGERR( "Failed to import python module %s for Tr2ActionPython", moduleName ); |
| 20 | return {}; |
| 21 | } |
| 22 | |
| 23 | BluePy classObj( PyObject_GetAttrString( module, className ) ); |
| 24 | if( !classObj || !PyCallable_Check( classObj ) ) |
| 25 | { |
| 26 | CCP_LOGERR( "Failed to get %s class from module %s for Tr2ActionPython", className, moduleName ); |
| 27 | return {}; |
| 28 | } |
| 29 | BluePy instance( PyObject_CallObject( classObj, nullptr ) ); |
| 30 | if( !instance ) |
| 31 | { |
| 32 | CCP_LOGERR( "Failed to instantiate Action class from module %s for Tr2ActionPython", moduleName ); |
| 33 | } |
| 34 | return instance; |
| 35 | } |
| 36 | |
| 37 | } |
| 38 |
no outgoing calls
no test coverage detected