-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_py27extend_main.cpp
More file actions
66 lines (55 loc) · 1.48 KB
/
Copy pathtest_py27extend_main.cpp
File metadata and controls
66 lines (55 loc) · 1.48 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "cwj_py27embed.h"
#include <Python.h>
#include "test_py27method.h"
// test c++ call python sample
int main(int argc, char* argv[])
{
py27init_module init_module;
py27embed embed;
embed.init(&init_module);
PyObject* pyobj_tuple = NULL;
// c++ call python
if ( 0 != embed.call_extend("bdh_encome", "hunt_everyhour_encome", "O", &pyobj_tuple))
{
// todo log
return -1;
}
if (NULL == pyobj_tuple)
{
// todo log
return -1;
}
int pytuple_size = PyTuple_Size(pyobj_tuple);
for (int idx = 0; idx < pytuple_size; ++idx)
{
int value = static_cast<int>( PyInt_AsLong( PyTuple_GetItem(pyobj_tuple, idx) ) );
// todo log int
}
embed.release_result(pyobj_tuple);
bool res = 0;
user_t* user = new user_t;
if (NULL == user)
{
// todo log
return -1;
}
user->money_ = 0;
int count = 99999;
// c++ call python
if ( 0 != embed.call_extend("bdh_encome", "pyadd_money_cb", "bli", &res, user, count))
{
// todo log
return -1;
}
// log user->money_ == 99999
// log res return by python pyadd_money_cb function: res == true || res == false
// py27embed::release_result(res); local POD
// c++ call python
if ( 0 != embed.call_extend("bdh_encome", "pyattr_list_cb"))
{
// todo log
return -1;
}
return 0;
}
// python file