ʵս¹¹½¨PythonºÍC++»ìºÏϵͳ
¹ØÓÚC++ºÍPythonÖ®¼ä»¥Ïàµ÷ÓõÄÎÊÌ⣬¿ÉÒÔ²éÕÒµ½ºÜ¶à×ÊÁÏ¡£±¾ÎĽ«Ö÷Òª´Ó½â¾öʵ¼ÊÎÊÌâµÄ½Ç¶È¿´ÈçºÎ¹¹½¨Ò»¸öPythonºÍC++»ìºÏϵͳ¡£
Á¦Îª 2009
Ò»¡¢¸ÅÄî
»ìºÏϵͳ£º²ÉÓöàÖÖÓïÑÔ¹¹½¨µÄϵͳ¡£±ÈÈçNative C++ºÍdotNetµÄ»ìºÏϵͳ£¬Python/LuaºÍC++µÄ»ìºÏϵͳ¡£
PythonºÍC++¸÷Óи÷µÄÓÅȱµã£¬¹¹½¨Á½Õß»ìºÏϵͳµÄÖ÷ҪĿµÄ¾ÍÊÇÀûÓÃPythonµÄÁé»îÐÔºÍC++¸ßЧÐÔ£¬Ôö¼Ó³ÌÐòµÄÀ©Õ¹ÐÔ¡£µ±È»»¹ÓÐÆäËûºÃ´¦£¬´Ë´¦¾Í²»Õ¹¿ªÌ¸ÁË¡£½Å±¾ÓïÑÔÓкܶ࣬ÖÁÓÚΪʲô²»²ÉÓÃÆäËûµÄ£¨ÈçLua¡¢RubyµÈ£©£¬ÕâÀïÒ²²»¿¼ÂÇ¡£½Å±¾ÓïÑԵIJÉÓÃÖ÷ÒªÊǸöÈËϲºÃµÄÎÊÌâ¡£²ÉÓÃLua¿ÉÒԲ鵽ºÜ¶à×ÊÁÏ£¬ÒÔÇ°Ò²ÔøÓÃLuaBindʵÏÖ¹ý¡£
¶þ¡¢ÏµÍ³¼Ü¹¹
»ìºÏϵͳ¿ÉÒÔ¼ò»¯³ÉÈçÏÂÄ£ÐÍ£º
ϵͳµÄÔËÐйý³ÌΪ£º
Ê×ÏÈÔÚÓ¦ÓóÌÐòÖÐǶÈë½Å±¾ÓïÑÔ½âÎöÆ÷£¬È»ºóÓýű¾ÓïÑÔÌṩµÄC/C++ API·â×°ÒÑÓеÄC++¹¦Äܿ⣬ÔÙÓýű¾µ÷Ó÷â×°µÄ·þÎñ¡£´Ëºó£¬Ó¦Óòã±ã¿ÉÒÔÖ´Ðнű¾ÀïµÄÄÚÈÝ£¬ÆäЧ¹ûÓëÓ¦ÓòãÖ±½Óµ÷Ó÷þÎñ²ãÀàËÆ¡£
Èý¡¢ÊµÏÖ
±¾ÀýÖвÉÓýű¾ÓïÑÔPython£¬Òò´ËÖ÷Òª¹¤×÷ΪÔÚÓ¦ÓòãǶÈëPython½âÎöÆ÷£¬ÓÃPython·â×°·þÎñ²ã¡£ÎªÁË˵Ã÷ÎÊÌ⣬ӦÓòãµÄʵÏÖΪPythonConsole.ex£¬·þÎñ²ãµÄʵÏÖΪMythma.dll£¬·â×°²ãΪMythmaPy.dll¡£
1¡¢¼Ù¶¨Mythma.dllÖеÄÒ»¸öÀàΪCHelloWorld£º
class MythmaAPI CHelloWorld
{
public:
CHelloWorld(void);
~CHelloWorld(void);
void SetId(int nId) { m_Id = nId;}
int GetId() const { return m_Id; }
private:
int m_Id;
};
2¡¢ÏÖÔÚÓÃBoost.Python·â×°¸ÃÀࣺ
#include "HelloWorld.h"
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(My
Ïà¹ØÎĵµ£º
¶à¸öÖ´ÐÐÏ߳̾³£Òª¹²ÏíÊý¾Ý£¬Èç¹û½ö½ö¶ÁÈ¡¹²ÏíÊý¾Ý»¹ºÃ£¬µ«ÊÇÈç¹û¶à¸öÏß³ÌÒªÐ޸Ĺ²ÏíÊý¾ÝµÄ»°¾Í¿ÉÄܳöÏÖÎÞ·¨Ô¤ÁϵĽá¹û¡£
¼ÙÈçÁ½¸öÏ̶߳ÔÏót1ºÍt2¶¼Òª¶ÔÊýÖµnum=0½øÐÐÔö1ÔËË㣬ÄÇôt1ºÍt2¶¼¸÷¶ÔnumÐÞ¸Ä10´ÎµÄ»°£¬ÄÇônum×îÖյĽá¹ûÓ¦¸ÃΪ20¡£µ«ÊÇÈç¹ûµ±t1È¡µÃnumµÄֵʱ£¨¼ÙÈç´ËʱnumΪ0£©£¬ÏµÍ³°Ñt1µ ......
ÎÒÃǾ³£»á²ÉÓÃÉú²úÕß/Ïû·ÑÕß¹ØϵµÄÁ½¸öÏß³ÌÀ´´¦ÀíÒ»¸ö¹²Ïí»º³åÇøµÄÊý¾Ý¡£ÀýÈçÒ»¸öÉú²úÕßÏ߳̽ÓÊÜÓû§Êý¾Ý·ÅÈëÒ»¸ö¹²Ïí»º³åÇøÀµÈ´ýÒ»¸öÏû·ÑÕßÏ̶߳ÔÊý¾ÝÈ¡³ö´¦Àí¡£µ«ÊÇÈç¹û»º³åÇøµÄ̫С¶øÉú²úÕߺÍÏû·ÑÕßÁ½¸öÒì²½Ï̵߳ÄËٶȲ»Í¬Ê±£¬ÈÝÒ׳öÏÖÒ»¸öÏ̵߳ȴýÁíÒ»¸öÇé¿ö¡£ÎªÁ˾¡¿ÉÄܵÄËõ¶Ì¹²Ïí×ÊÔ´²¢ÒÔÏàͬËٶȹ¤×÷µÄ¸÷Ï̵߳ĵ ......
http://hi.baidu.com/guzhilei1986/blog/item/8969b4debe99e150ccbf1ae7.html
º¯Êý ÃèÊö
int(x [,base ]) ......
from: http://www.chinesepython.org/pythonfoundry/tut2.3/tmp/multiple.html
9.5.1 ¶à¼Ì³Ð Multiple Inheritance
Python supports a limited form of multiple inheritance as well. A class definition with multiple base classes looks as follows:
PythonͬÑùÓÐÏÞµÄÖ§³Ö¶à¼Ì³ÐÐÎʽ¡£¶à¼Ì³ÐµÄÀඨÒåÐÎÈçÏÂÀ ......
×î½ü¶Ôpython²úÉúÁËÐËȤ£¬ÓÚÊÇ´ÓÍøÉÏÏÂÔØÁË»ù±¾PYTHONµÄÊéºÍÎĵµ£¬¿ªÊ¼ÁËPYTHONµÄѧϰ£¬·¢ÏÖPYTHONÖеÄlist¶ÔÏóµÄ¹¦ÄÜʵÔÚÊǷdz£Ç¿´ó£¬±à³ÌÆðÀ´±ÈÆäËûµÄ³ÌÐòÓïÑÔ¶ÔÁбíµÄ²Ù×÷Òª·½±ãµÄ¶à¡£
ÔÚpythonÖж¨ÒåÒ»¸öÁбíÖ»ÐèÒªÈçÏÂÓï¾ä
li = ["a","b","c","d"]
listÓÐÐí¶àµÄº¯Êý¿ÉÒÔÓÃÀ´½øÐжÔÁбíµÄ²Ù×÷£¬Èçextend,append,inse ......