I’m writing a game in c++ using boost.python library as script system.
I have an abstract class Object. Now I create new class, inherit it from Objects and write somewhere Object *obj = new SomeCoolObject();
I also have a map of objects: map<string, Object*> objects. So after making object I do: objects.insert("name", obj);.
Don’t say anything about freeing memory, etc. I hided that part to get less code (I’m using smart pointers).
So the question is:
I want to have a folder with python-files. In each file I describe some Object-derived class like:
class SomeCoolObject(Object):
...
How to bind that class into c++? Or in another words: how to say into c++ program that there is such new class.
And once again: there colud be a few py-files with such classes and I have to export all of them.
Any ideas, guys?
If you’ve already loaded the module (e.g., using
boost::python::import("module_name")), you should be able to reference any classes in it via theattr()member function. Generally I write a wrapper function around it, since it can raise an exception if the class (or any other attribute, for that matter) doesn’t exist. For example: