脚本系统:c++内嵌python
脚本系统:c++内嵌python
|
// liquidx.cpp : Defines the entry point for the console application. #include "stdafx.h" using namespace std; PyObject * RepeatString (PyObject *pSelf, PyObject *pParams)
//create a function table //initial the module with the function table PyObject *pName = PyString_FromString("helloworld");
pstr = PyDict_GetItemString(pDict, "PrintStuff");//get the function with the dict
//Py_XDECREF(pFunc); |
Helloworld.py 如下:
import HostAPI
def PrintStuff():
global RepCount
RepCount = HostAPI.RepeatString("String repetition", 4)
使用BOOST::PYTHON来写脚本的方法:
|
# include <boost/python.hpp> class sample sample(int v=0);
int sample::GetValue() void sample::SetValue(int v) sample::~sample(void) namespace boost{ register_ptr_to_python< pSample >(); }
try main_namespace["sample"] = ptr; fprintf(stderr,"Before finalize
"); |
Sample.py 如下:
print "print in python",sample.get()
print sample
sample.set(12345)
结果:
print in python 25
<pySample.sample object at 0x00C4CFB0>
print in c:12345 2
Before finalize
Delete sample address is b46638
After finalize
发布人信息
- 联系人:wumingwei 查看该用户发布的所有信息
- 电话:
- 邮箱:
- 地址:



