ffpython is a C++ lib, which is to simplify tasks that embed Python and extend Python. As the author, I am a developer for MMO server. Mainly I use C++ to implement part that needs to response user's requests in realtime, while other logic part that needs to be modified frequently is implemented by Python. Python makes it possible to reload our part of the server when the server is running. Python is so easy that even my colleague with no programing skills can implement some npc script. When I was first in charge of integrating Python runtime interpreter to our C++ server, I used Boost.python. Somehow Boost.python helped me solve most problems about Python API especially parts of Python reference. But Boost.python is not perfect.
static
function and class in runtime. Boost.python recommends to use dynamic library to extending python.Firstly, I implemented it just for converting data between C++ STL container and python object. Some of my colleagues have writes a lot of code using Python API directly. But there is some trap in some Python API even engineers who have a lot of experience using Python may have lost. PyDict_SetItem will auto increase reference key and value arguments, but other Python builtin structure API like PyTuple_SetItem
will not increase reference the argument. It will cause memory leak. So I wanted to wrap operations about converting data between C++ STL container and Python builtin structure. Finally, I found some elegant ways to wrap embedding Python and extending Python by C++ template skills. So that is how FFPyhton was born.
Sometimes I think it's easier to show codes to readers here. ^_^. But it will be forbidden by administrator if I post lots of code. O(n_n)O~. So see code files or Github.
When Embedding Python, such functions are most needed.
exception.what()
.printf(<>(, a1 = ; a2 = ; a3 = <>(, <> a1;a1.push_back();a1.push_back(<> a2; a2.push_back();a2.push_back(<list<> ><>(, <, list<vector<> > >= ffpython.call<ret_t>(, );
ffpython recommends to register C++ function/class in runtime. It works to design and develop MMO game server. So that is common use for me. There are some key points when embedding Python.
static
function. C++ builtin types and STL container can be as arguments.Register C++ static
function, all base type supported. Arg num can be nine.
print_val( a1, a2, & a3, vector<>& ffpython.reg(&print_val, );
Register C++ class, Python can use it just like builtin types.
~ get_value() { set_value( v_) { m_value = test_stl(map<, list<> >& dumy_t: ~ foo_t* obj_test(dumy_t* test_register_base_class(ffpython_t&<foo_t, PYCTOR()>(&foo_t::get_value, &foo_t::set_value, &foo_t::test_stl, &foo_t::m_value,