research:embeddedpython
차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판이전 판다음 판 | 이전 판 | ||
research:embeddedpython [2014/02/03 07:07] – [C의 데이터를 파이썬의 객체형으로 표현] changwoo | research:embeddedpython [2014/10/09 21:24] (현재) – 바깥 편집 127.0.0.1 | ||
---|---|---|---|
줄 481: | 줄 481: | ||
<code cpp call.cpp> | <code cpp call.cpp> | ||
- | #include < | ||
- | #include < | ||
#include < | #include < | ||
- | #include <string> | + | #include <boost/ |
- | using namespace boost:: | + | namespace |
+ | |||
+ | void workaround_for_local_modules() | ||
+ | { | ||
+ | PyRun_SimpleString( | ||
+ | " | ||
+ | " | ||
+ | } | ||
int main(int argc, char** argv) | int main(int argc, char** argv) | ||
{ | { | ||
- | if(argc < 3) { | + | |
- | std::cerr << | + | |
- | return 1; | + | return 1; |
- | } | + | } |
- | + | ||
Py_Initialize(); | Py_Initialize(); | ||
+ | workaround_for_local_modules(); | ||
- | object | + | try { |
- | sys.attr(" | + | bp::object |
+ | bp:: | ||
+ | bp:: | ||
+ | |||
+ | module_name | ||
+ | module = bp:: | ||
+ | func = module.attr(argv[2]); | ||
+ | |||
+ | if(func && PyCallable_Check(func.ptr())) { | ||
+ | bp:: | ||
+ | |||
+ | tuple = bp:: | ||
+ | for(int i = 0; i < argc - 3; ++i) { | ||
+ | PyObject* arg; | ||
+ | arg = PyInt_FromLong(atoi(argv[i+3])); | ||
+ | PyTuple_SetItem(tuple.ptr(), i, arg); | ||
+ | } | ||
+ | |||
+ | bp:: | ||
+ | int value; | ||
+ | |||
+ | valueObj = bp:: | ||
+ | value = bp:: | ||
+ | |||
+ | std:: | ||
+ | } | ||
+ | |||
+ | } catch(bp:: | ||
+ | PyErr_Print(); | ||
+ | } | ||
- | object module = import(argv[1]); | ||
- | object func = module.attr(argv[2]); | ||
- | |||
- | int r = extract< | ||
- | std::cout << r << std::endl; | ||
Py_Finalize(); | Py_Finalize(); | ||
+ | return EXIT_SUCCESS; | ||
} | } | ||
</ | </ | ||
+ | |||
+ | '' | ||
research/embeddedpython.1391411279.txt.gz · 마지막으로 수정됨: 2014/10/09 21:23 (바깥 편집)