9 static PyObject*
GetFunction(PyObject* self, PyObject* args)
12 std::string scriptName = pyObBuilder.
getStringValue(PyTuple_GetItem(args, 0),
"Parameter 1");
13 std::string functionName = pyObBuilder.
getStringValue(PyTuple_GetItem(args, 1),
"Parameter 2");
14 PyObject*
module = PyImport_ImportModule(scriptName.c_str());
15 assert(module !=
nullptr);
16 PyObject* function = PyObject_GetAttrString(module, functionName.c_str());
17 assert(function !=
nullptr);
24 if (!PyArg_ParseTuple(args,
"i", &command))
28 return PyLong_FromLong(command + 13);
33 return PyUnicode_FromString(
"Hello from the extension");
40 int parameter1 = pyObBuilder.
getInt32Value(param1,
"Parameter 1");
42 int parameter2 = pyObBuilder.
getInt32Value(param2,
"Parameter 2");
44 std::string parameter3 = pyObBuilder.
getStringValue(param3,
"Parameter 3");
46 int result = (parameter1 + parameter2) * 2;
47 if (parameter3 ==
"Suppe")
57 {
"WithOneParameter",
WithOneParameter, METH_VARARGS,
"Test function with one parameter."},
58 {
"WithoutParameter",
WithoutParameter, METH_NOARGS,
"Test function without parameter."},
59 {
"WithMultipleParameter",
WithMultipleParameter, METH_VARARGS,
"Test function with multiple parameter."},
60 {
"GetFunction",
GetFunction, METH_VARARGS,
"Test function getter."},
68 PyModuleDef_HEAD_INIT,
Builder to transfer typically used PyObjects to c++ types and vice versa.
int result
Definition dllmain.cpp:82
Definition CPythonObjectBorrowed.h:15
PyObjects don't distingiush between float and double and int32 and int64. All floating point values a...
Definition PythonObjectBuilder.h:28
int32_t getInt32Value(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:173
std::string getStringValue(const CPythonObject &pValue, const std::string &varName)
Definition PythonObjectBuilder.cpp:191
CPythonObjectNew setInt32(const int32_t value)
Definition PythonObjectBuilder.cpp:507
Definition TestingPythonExtensions.h:7
static PyObject * WithMultipleParameter(PyObject *self, PyObject *args)
Definition TestingPythonExtensions.h:36
static std::string testModuleDescription
Definition TestingPythonExtensions.h:65
static PyMethodDef OTMethods[]
Definition TestingPythonExtensions.h:55
static PyObject * WithoutParameter(PyObject *self, PyObject *args)
Definition TestingPythonExtensions.h:31
PyMODINIT_FUNC PyInit_Testing(void)
Definition TestingPythonExtensions.h:77
static struct PyModuleDef TestModule
Definition TestingPythonExtensions.h:67
static PyObject * WithOneParameter(PyObject *self, PyObject *args)
Definition TestingPythonExtensions.h:21
static PyObject * GetFunction(PyObject *self, PyObject *args)
Definition TestingPythonExtensions.h:9