HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PY_CallMethod.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  * This file contains functionality to call methods on python objects,
8  * specifically when arguments need to be passed to the call.
9  *
10  * You should only need to include this file in .C files, not in .h files.
11  */
12 
13 #ifndef __PY_CallMethod_h__
14 #define __PY_CallMethod_h__
15 
16 #include "PY_CPythonAPI.h"
17 #include "PY_AutoObject.h"
18 #include "PY_InterpreterAutoLock.h"
19 #include "PY_Python.h"
20 #include "PY_Result.h"
21 
22 /// Given an (opaque) Python object, call one of its methods
23 /// and return its result, converting to the desired type.
24 ///
25 /// This is identical to PYcallMethodOnPythonObject in PY_Python.h
26 /// except that it uses a template parameter pack to forward arguments
27 /// to the function call.
28 ///
29 /// NOTE: there is an issue with clang (pre-v11) that means you can *not*
30 /// make any of the arguments have default values
31 /// (see https://bugs.llvm.org/show_bug.cgi?id=23029#c3)
32 template <typename ...Args>
34  void *opaque_python_object, const char *method_name,
35  PY_Result::Type desired_result_type,
36  const char *format, Args&&... args)
37 {
38  PY_InterpreterAutoLock python_lock;
39  UT_ASSERT(opaque_python_object);
40  PY_PyObject *python_object = (PY_PyObject *)opaque_python_object;
41  PY_AutoObject result_object = PY_PyObject_CallMethod(
42  python_object, method_name, format, std::forward<Args>(args)...);
43  if (!result_object)
44  return PYextractPythonException();
45  return PYextractResultFromPythonObject(result_object, desired_result_type);
46 }
47 
48 #endif
PY_API PY_Result PYextractResultFromPythonObject(void *opaque_python_object, PY_Result::Type desired_result_type)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
PY_PyObject
PY_API PY_PyObject * PY_PyObject_CallMethod(PY_PyObject *o, const char *name, const char *format,...)
PY_API PY_Result PYextractPythonException()
**If you just want to fire and args
Definition: thread.h:609
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
PY_Result PYcallMethodOnPythonObjectWithArgs(void *opaque_python_object, const char *method_name, PY_Result::Type desired_result_type, const char *format, Args &&...args)
Definition: PY_CallMethod.h:33