-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathc_function.cpp
40 lines (33 loc) · 869 Bytes
/
c_function.cpp
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
#include<bits/stdc++.h>
#include <cstdio>
#include <string>
#include <Python.h>
#include "pyhelper.hpp"
using namespace std;
int main() {
setenv("PYTHONPATH", ".", 1);
CPyInstance hInstance;
CPyObject pName = PyUnicode_FromString("DQN");
CPyObject pModule = PyImport_Import(pName);
if(pModule)
{
CPyObject pFunc = PyObject_GetAttrString(pModule, "initialize");
if(pFunc && PyCallable_Check(pFunc))
{
// CPyObject args = PyTuple_Pack(4,PyFloat_FromDouble(2.0),PyFloat_FromDouble(4.0),PyFloat_FromDouble(6.0),PyFloat_FromDouble(8.0));
CPyObject pValue = PyObject_CallObject(pFunc, NULL);
cout<<"FROM C: Called";
printf("C: getInteger() = %ld\n", PyLong_AsLong(pValue));
}
else
{
printf("ERROR: function getInteger()\n");
}
}
else
{
printf("ERROR: Module not imported\n");
}
return 0;
return 0;
}