当前位置:七道奇文章资讯编程技术VC/C++编程
日期:2011-03-22 13:54:00  来源:本站整理

脚本系统:c++内嵌python[VC/C++编程]

赞助商链接



  本文“脚本系统:c++内嵌python[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

// liquidx.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <boost/python/def.hpp>
#include <boost/python/module.hpp>
#include <boost/python/args.hpp>
#include <boost/python/class.hpp>
#include <boost/python/str.hpp>
#include <boost/python/dict.hpp>
#include <iostream>
#include <string>
#include <list>
#include <map>

using namespace std;

PyObject * RepeatString (PyObject *pSelf, PyObject *pParams)
{
char *pstrString;
int iRepCount;
PyArg_ParseTuple(pParams, "si", &pstrString, &iRepCount);
for (int i = 0; i < iRepCount; i++)printf("---%d\n", i);
return PyInt_FromLong(iRepCount);
}


int _tmain(int argc, _TCHAR* argv[])
{
Py_Initialize();
Py_IsInitialized();
PyImport_AddModule("HostAPI");

//create a function table
PyMethodDef HostAPIFuncs [] =
{
{"RepeatString", RepeatString, METH_VARARGS, NULL},
{NULL, NULL, NULL, NULL}
};

//initial the module with the function table
Py_InitModule("HostAPI", HostAPIFuncs);

PyObject *pName = PyString_FromString("helloworld");
PyObject * pModule = PyImport_Import(pName);
PyObject *pstr= NULL, *pDict= NULL;


//get the module dict
pDict = PyModule_GetDict(pModule);

pstr = PyDict_GetItemString(pDict, "PrintStuff");//get the function with the dict
PyObject_CallObject ( pstr, NULL ); //call the function


PyObject *pFunc = PyDict_GetItemString(pDict, "RepCount");
int  as = PyInt_AS_LONG(pFunc);
printf( "**************************%d", as );

//Py_XDECREF(pFunc);
Py_XDECREF(pstr);
//Py_XDECREF(pDict);
Py_XDECREF(pModule);
Py_XDECREF(pName);
Py_Finalize(); // 排除
getchar();
return 0;
}


  以上是“脚本系统:c++内嵌python[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:

  • 脚本系统:c++内嵌python
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .