Recently done the project wants to play, point flexible routines, processing logic to let the business custom to go, so from the elder brother game service came to think of the load script routines.
Everyone on Earth knows that Lua uses the most of the script in the game, but this time our project is monitoring and alerting, there may be complex operations, so the sub-LUA library is poorer, choose to use Python, so I need to make Python and C + + to do the interaction.
My requirement is this: 1 The main program is C + +, the user will go to the main program registration, this time the Python script is registered.
2 in some cases to run the Python script, Python will call a specific C + + interface, complete some of the python is not easy to complete functions, such as the operation of the database, call the text interface and so on.
Lazy people do not want to write the original ecological code, see that one by one C + + to Python registration interface do not love to do, find a Chinese writing three-party library Ffpython, ran his example, or good, very simple, can complete C + + static function, C + + class want to register Python , with this, by the way, his example in the Test_reg_function interface of the second parameter should be passed int, do not know that the script is written in a double row, resulting in an exception.
ffpython_t::init_py();
ffpython_t::add_path("/USERS/BOJUE/SENTRY2/SENTRY-ALARM/SRC") ;
Cinterface_api M_api;
python. Reg_class < Cinterface_api,pyctor() > ("Cinterface_api")
. Reg (&cinterface_api::getgroupinfo,"GetGroupInfo") ;
python. Init ("db_operate");
python. Pager < void > ("fftest","Test_db_api", &m_api);
ffpython_t::init_py();
So a few lines of code is OK, you can cinterface_api the object registered to Python, the need for detailed research friends to download his code to see the example bar. Very simple.
C + + interacts with Python