MCPcopy Create free account
hub / github.com/carbonengine/trinity / CreateInstance

Function CreateInstance

trinity/Controllers/Actions/Tr2ActionPython.cpp:11–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9{
10
11BluePy 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

Callers 4

InstantiateObjectMethod · 0.85
AddInstanceTransformMethod · 0.85
CreateInstancesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected