From super24bitsound at hotmail.com Fri Jul 1 01:52:46 2011 From: super24bitsound at hotmail.com (Jay Riley) Date: Thu, 30 Jun 2011 19:52:46 -0400 Subject: [C++-sig] Boost Python - Implementing a Cloning function Message-ID: I'm trying to implement a Cloning function for one of my classes I want to extend to Python. Extending the classes in C++ is easy as I can just override the Clone function, but it's definitely not working like that for Python. Here's the code, with unimportant detail ommitted. template class Cloneable { public: typedef boost::shared_ptr ClonePtr; virtual ClonePtr Clone() = 0; }; class Action : public Cloneable { public: virtual ClonePtr Clone() override; } Action::ClonePtr Action::Clone() { return ClonePtr(new Action(*this)); } class Attack : public Action { public: virtual ClonePtr Clone() override; } Attack::ClonePtr Attack::Clone() { return Attack::ClonePtr(new Attack(*this)); } struct AttackWrapper : Game::Battles::Actions::Attack { Cloneable::ClonePtr AttackWrapper::Clone() { return call_method::ClonePtr>(self, "Clone"); } Cloneable::ClonePtr AttackWrapper::CloneDefault() { return this->Action::Clone(); } } I expose it like follows: class_, std::auto_ptr, bases >("Attack") .def(init<>()) .def(init()) .def("Clone", &Attack::Clone, &AttackWrapper::CloneDefault) ; In my python file: class ScriptedAttack(Attack): def __init__(self, Type, ID, Name, Flags, Power, MPCost = 0, SPCost = 0, Accuracy = 0.9, CritChance = 0.1, DefineOwnUse = False, EleWeights = None, StatusEffectChances = None): #initialization logic def Clone(self): #return ScriptedAttack(self) #what to put here? Fire = ScriptedAttack(ActionType.MagicAction, PrimaryEngine.GetUID(), "Fire", AttackFlags.Projectile | AttackFlags.Elemental, 32, 14, 0, 1.0, 0.1, False, {Elements.Fire: 1.0}) Fire2 = Fire.Clone() ActLibrary.AddAttack(Fire) ActLibrary.AddAttack(Fire2) I'm really not sure how to do this - I'm stuck on what I need to put under def Clone. I know I can't have multiple inits, and I can't define a copy constructor. I know about the copy function in python, but the Action class (base of Attack) has a custom copy constructor I need to be called. Can someone help me out with how to do this? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From avibahra at googlemail.com Mon Jul 4 10:48:21 2011 From: avibahra at googlemail.com (Avi Bahra) Date: Mon, 4 Jul 2011 09:48:21 +0100 Subject: [C++-sig] bjam broken for installing python extensions Message-ID: Using boost 1.45, on linux suse, gcc I am trying to install a shared library(python extension), and I want to hard code the path to the boost python shared library, so that my users don't need to specify LD_LIBRARY_PATH. >From reading the bjam documentation, I should be using . This works for an executable which needs to hard code a path to a shared library. However it does not work for a shared library that needs to embed a hard coded path to another shared library. (i.e boost python shared library). install install-py : Pyext//ecflow : on PYTHON_EXTENSION SHARED_LIB $(PYTHON_INSTALL_DIR) $(PYTHON_INSTALL_DIR) My expectation was that use of during a install should force a re-link, with and add the equivalent of -Wl,rpath. However it does nothing. The hacky way to get around this bug appears to be use when building the extension. Hacky because I want to use development lib, and not the installed hard code path. Even this hack does not work on other unix flavours, so you are pretty much hosed in trying to use bjam for installation of python extensions. It also appears that does not apply to python extensions. The only unix flavour where this works is HPUX. I am sure this problem is not new, so I'm wondering how do other people handle installation of boost python extensions. Is there no alternative to LD_LIBRARY_PATH ? Best regards, Ta, Avi From betoparcus at hotmail.com Tue Jul 5 15:01:00 2011 From: betoparcus at hotmail.com (Robert Parcus) Date: Tue, 5 Jul 2011 13:01:00 +0000 Subject: [C++-sig] Wrapping types with boost.python Message-ID: Hello all, I'm new here :) I'm a CS student doing my internship and I'm working on wrapping the glm library (http://glm.g-truc.net/) to export it to python. (eg. I have a lot of time to do it, but I'm learning while I'm doing it)It's an open source library and the results (if any) of my work will go to the same field. I've spent the last few weeks familiarising with boost.python and I've spent a large amount of time looking for and reading tutorials and examples but now I feel like I have to ask you for some help, if that's ok. glm is a header only library and it has many types (mostly vectors(n), matrices(n,m)...) and many many functions to play with them. It also makes heavy use of templates. While exposing the functions has been pretty easy, I was not able yet to expose a single type. (I have been exposing the functions and specializing them only with int, double, etc types not the vectors and matrices, which are the most important types for me actually... I did it as a proof of concept, and because I'm stuck in this "exposing types" problem since a long time...) As an example, on line 38 of this code http://glm.g-truc.net/api-0.9.1/a00127_source.html is the definition of vec2. All glm types are pretty similar to this and if I could have some insights on how to wrap something like this the rest would be almost "not very hard" for me to do. Thanks in advance, Robert ps: I also checked py++ in the beginning of my researches. I couldn't make it work at the time, and I'm not even sure a library like glm could be easily wrapped using it. Any advices about that as well? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan at seefeld.name Tue Jul 5 15:23:53 2011 From: stefan at seefeld.name (Stefan Seefeld) Date: Tue, 05 Jul 2011 09:23:53 -0400 Subject: [C++-sig] Wrapping types with boost.python In-Reply-To: References: Message-ID: <4E131069.6010608@seefeld.name> Hi Robert, On 2011-07-05 09:01, Robert Parcus wrote: > > While exposing the functions has been pretty easy, I was not able yet > to expose a single type. (I have been exposing the functions and > specializing them only with int, double, etc types not the vectors and > matrices, which are the most important types for me actually... I did > it as a proof of concept, and because I'm stuck in this "exposing > types" problem since a long time...) Could you elaborate on what problems you have with exposing types ? What exactly did you try that didn't work ? > > As an example, on line 38 of this code > http://glm.g-truc.net/api-0.9.1/a00127_source.html is the definition > of vec2. All glm types are pretty similar to this and if I could have > some insights on how to wrap something like this the rest would be > almost "not very hard" for me to do. tvec2 itself isn't a type. You need to instantiate it to get a type that you can expose to Python. Then the normal rules should work just fine: class_ > f_tvec2("fvec2"); float (tvec2::*swizzle_1)(comp) = &tvec2::swizzle; f_tvec2.def("swizzle", swizzle_1); I assume you'd like to do this for many different value-types, so it might be best to wrap this in a function template: template void define_vec2(char const *name) { typedef tvec2 vec2_type; class_ vec2(name); float (vec2_type::*swizzle_1)(comp) = &vec2_type::swizzle; vec2.def("swizzle", swizzle_1); //... } and then call that function for all the value-types you want: define_vec2("fvec2"); define_vec2("ivec2"); //... HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From betoparcus at hotmail.com Tue Jul 5 17:57:31 2011 From: betoparcus at hotmail.com (Robert Parcus) Date: Tue, 5 Jul 2011 15:57:31 +0000 Subject: [C++-sig] Wrapping types with boost.python Message-ID: Thank you Stephan, a few lines of your code have triggered a lot of sparks in my brain. >template >void define_vec2(char const *name) >{ > typedef tvec2 vec2_type; > class_ vec2(name); > float (vec2_type::*swizzle_1)(comp) = &vec2_type::swizzle; > vec2.def("swizzle", swizzle_1); > //... >} > >and then call that function for all the value-types you want: > > define_vec2("fvec2"); > define_vec2("ivec2"); > //... I see that the template function approach is very useful for the number of value-types I have to work with (you guessed right), but I still have problems... 1) on the python interpreter, i have: >>> fvec2 < class '_ext.fvec2' > >>> int < type 'int' > Is there a standard way to make fvec2 become a real "type" in python, just like int? 2) I still can't do this from python >>> a = fvec2 (4.0,2.0) I realise that what I may be missing is .def("__init__", ... ) somewhere, but I don't know where, and how to initialize it properly. ( Also, I had to exclude the "swizzle" part(last 2 lines of the first section), because otherwise the program would no compile, but that's not the important part right? Thanks again,Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan at seefeld.name Tue Jul 5 18:08:07 2011 From: stefan at seefeld.name (Stefan Seefeld) Date: Tue, 05 Jul 2011 12:08:07 -0400 Subject: [C++-sig] Wrapping types with boost.python In-Reply-To: References: Message-ID: <4E1336E7.1040001@seefeld.name> On 2011-07-05 11:57, Robert Parcus wrote: > > I see that the template function approach is very useful for the > number of value-types I have to work with (you guessed right), but I > still have problems... > > 1) on the python interpreter, i have: > >>> fvec2 > < class '_ext.fvec2' > > >>> int > < type 'int' > > > Is there a standard way to make fvec2 become a real "type" in python, > just like int? What is fvec2 missing that makes you think it's not a "real type" ? > > 2) I still can't do this from python > >>> a = fvec2 (4.0,2.0) > > I realise that what I may be missing is .def("__init__", ... ) > somewhere, but I don't know where, and how to initialize it properly. ( That's right, you need to add appropriate constructors. I'm again not sure what specific issues you are facing, and what exactly doesn't work, making it hard to help. Have you followed the tutorial (http://www.boost.org/doc/libs/1_46_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.constructors) ? > > Also, I had to exclude the "swizzle" part(last 2 lines of the first > section), because otherwise the program would no compile, but that's > not the important part right? That was just meant to illustrate how to add member functions / methods to a class. I admit I didn't test the code I typed, so there may be typos in it. Sorry for that. Stefan -- ...ich hab' noch einen Koffer in Berlin... From brokenn at gmail.com Wed Jul 6 12:56:39 2011 From: brokenn at gmail.com (Brian O'Kennedy) Date: Wed, 6 Jul 2011 11:56:39 +0100 Subject: [C++-sig] Miscellaneous Boost.Python Utilities In-Reply-To: <4BEC9F19.9020300@gmail.com> References: <4BEC9F19.9020300@gmail.com> Message-ID: Hi Jim, I've been trying out your python extensions and find them very useful to ease the wrapping process. I did however find a problem with the behaviour of the container_from_python_sequence converter. When having two overloaded functions, one of which expects a container of TestObjects and the other a single TestObject, I get this error in Python when calling the overloaded function with a single TestObject. TypeError: object of type 'TestObject' has no len() This is due to the use of the len() function on a non-sequence in the 'convertible' method of container_from_python_sequence. The other issue is that the type of objects in the sequence is only checked if the sequence has more-than-one item, and not when it only contains one. I've made a couple of changes, included in the patch below. (A) Check if the input is in fact a sequence. (B) Check the contained type when the sequence length is non-zero Cheers Brian -----------------container.hpp---------------------------------- @@ -37,8 +37,10 @@ struct container_from_python_sequence { static void* convertible(PyObject * obj) { try { + if (!PySequence_Check(obj)) + return NULL; object sequence(handle<>(borrowed(obj))); - if (len(sequence) > 1) { + if (len(sequence) > 0) { if (!extract(sequence[0]).check()) return NULL; } --------------------------------------------------------- On 14 May 2010 01:53, Jim Bosch wrote: > > In the hope that others might find them useful, and perhaps contribute some of their own, I've posted a collection of miscellaneous Boost.Python extensions I've been using at the Boost sandbox: > > http://svn.boost.org/svn/boost/sandbox/python_extensions > > Features include: > > - Conversions between STL containers and Boost.Range iterator ranges and Python builtins like list, tuple, and dict. > > - Conversions between Boost.Fusion sequences and Python tuples. > > - A third solution to the const shared_ptr problem (see http://language-binding.net/pyplusplus/troubleshooting_guide/shared_ptr/shared_ptr.html) that isn't evil (I don't think) and doesn't involve changing the Boost.Python library itself - it simply doesn't use register_ptr_to_python to register the conversion. > > More info is available in the README file. > > Also, I'm sure many of the regulars on this list have their own similar extensions, and I'd love to see them collected in one place. ?If you'd like to add your collection to mine, or have a suggestion for some other place I should put my collection, please let me know. ?I would like to limit this collection to simple things that don't depend on non-Boost libraries, however. > > > Jim Bosch > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From alexey.akimov85 at gmail.com Sun Jul 10 17:01:35 2011 From: alexey.akimov85 at gmail.com (Alexey Akimov) Date: Sun, 10 Jul 2011 10:01:35 -0500 Subject: [C++-sig] boost testing uses non-existing location Message-ID: Dear all, I encountered the following problem. When I compile and try to run the python extension with bjam and boost.testing suite the latter tries to use the previous location of my python installation. As it follows from the output the testing suit tries to run this version of python --> /users/aa7/Python_m64/bin/python2.6, but before installing it there I had similar version of python installed in here --> /users/aa7/bin. The last location was then completely removed, so now I am trying to use the former one. However, it looks like boost have remembered the previous location and tries to invoke the python executable from there too. This is obvious from the following line of the output: "/users/aa7/Python_m64/bin/python2.6" "/users/aa7/bin" "test.py" > ... I do not have and /users/aa7/bin directory at all. What should I change to get rid of referencing to that directory? Or how should I fix the problem? So here is the most informative part of the output: .... gcc.link.dll bin/gcc-4.1.2/release/address-model-64/myextension.so capture-output bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext ====== BEGIN OUTPUT ====== /users/aa7/Python_m64/bin/python2.6: can't open file '/users/aa7/bin': [Errno 2] No such file or directory EXIT STATUS: 2 ====== END OUTPUT ====== LD_LIBRARY_PATH=/users/aa7/Soft/boost_1_39_0/bin.v2/libs/python/build/gcc-4.1.2/release/address-model-64:/users/aa7/Soft/boost_1_39_0/bin.v2/libs/regex/build/gcc-4.1.2/release/address-model-64:/users/aa7/Soft/boost_1_39_0/libs/python/example/MyExtension/bin/gcc-4.1.2/release/address-model-64:/usr/bin:/usr/lib:/usr/lib32:/usr/lib64:$LD_LIBRARY_PATH export LD_LIBRARY_PATH PYTHONPATH=bin/gcc-4.1.2/release/address-model-64 export PYTHONPATH "/users/aa7/Python_m64/bin/python2.6" "/users/aa7/bin" "test.py" > "bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext.output" 2>&1 status=$? echo >> "bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext.output" echo EXIT STATUS: $status >> "bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext.output" if test $status -eq 0 ; then cp "bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext.output" "bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext" fi verbose=1 if test $status -ne 0 ; then verbose=1 fi if test $verbose -eq 1 ; then echo ====== BEGIN OUTPUT ====== cat "bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext.output" echo ====== END OUTPUT ====== fi exit $status ...failed capture-output bin/test_ext.test/gcc-4.1.2/release/address-model-64/test_ext... ...failed updating 1 target... ...skipped 1 target... ...updated 147 targets... -------------- next part -------------- An HTML attachment was scrubbed... URL: From Manuela.Kaelberer at LBBW.de Wed Jul 13 16:19:44 2011 From: Manuela.Kaelberer at LBBW.de (Manuela Kaelberer) Date: Wed, 13 Jul 2011 16:19:44 +0200 Subject: [C++-sig] wrap C++ function with private copy constructor In-Reply-To: References: Message-ID: Hi, I have to wrap a C++ API for Python. There are a couplt of difficulties: - The C++ classes have private constructors. - pointers to class instances are parameters for functions - callbacks that are initiated by the C++ side, but call functions implemented on the Python side. How do I do that? Any hint is appreciated. Example: class X { public: X(); virtual ~X(); virtual callback(A* a) = 0; }; class Y::X { Y(); ~Y(); callback(A* a); } class M { public: M(); virtual ~M() protected: M(const M& m); M & operator=(const M& m); } class N::M { public: N() virtual ~N() private N(const N& n); N& operator=(const N& n); } class A: { public: A(); protected: A(const A& a); A& operator=(const A& a) } class B::A { public: B(); void create(Y* y, M* m); private: B(const B& b); B& operator=(const B& b); }; ===================================================== Python: class Y: __init__(): pass def callback(a): print "callback implemented in python" y=Y() n=N() b=B() b.create(y, n) The callback function y.callback(A* a) will be called by the C++ API when an event occurs. Kind Regards Manuela Kaelberer ---------------------------------------------- Manuela K?lberer IT FM Consulting (1432 H) Landesbank Baden-W?rttemberg Am Hauptbahnhof 2 D-70173 Stuttgart Phone +49 711 127-43753 Fax +49 711 127-437 59 manuela.kaelberer at LBBW.de www.LBBW.de Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart From lists_ravi at lavabit.com Wed Jul 20 03:49:54 2011 From: lists_ravi at lavabit.com (Ravi) Date: Tue, 19 Jul 2011 18:49:54 -0700 Subject: [C++-sig] wrap C++ function with private copy constructor In-Reply-To: References: Message-ID: <201107191849.54514.lists_ravi@lavabit.com> On Wednesday 13 July 2011 07:19:44 Manuela Kaelberer wrote: > I have to wrap a C++ API for Python. There are a couplt of difficulties: > - The C++ classes have private constructors. Use boost:python::no_init in class_<...>. > - pointers to class instances are parameters for functions This is not a problem since boost.python handles pointers and references in function parameter lists automatically. > - callbacks that are initiated by the C++ side, but call functions > implemented on the Python side. This is a little tricky but is well-covered in the documentation: http://www.boost.org/doc/libs/1_47_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.virtual_functions_with_default_implementations Regards, Ravi From rstarfield at gmail.com Thu Jul 28 23:37:38 2011 From: rstarfield at gmail.com (Richard Starfield) Date: Thu, 28 Jul 2011 14:37:38 -0700 Subject: [C++-sig] Cannot import .pyd generated using Boost.Python on Windows XP using Mingw Message-ID: Hi, I tried building the hello world tutorial example using bjam and it seemed to pass the tests - the generated hello.output file contains: > hello, world > > EXIT STATUS: 0 However when I copy the resulting hello_ext.pyd to the Python DLL directory and try to >>> import hello_ext within Python, I get the message "ImportError: DLL load failed: The specified module could not be found." How do I fix this? Thanks, Richard. From blemidon at gmail.com Sat Jul 30 11:24:43 2011 From: blemidon at gmail.com (=?ISO-8859-1?Q?Horv=E1th?= Imre) Date: Sat, 30 Jul 2011 11:24:43 +0200 Subject: [C++-sig] create module in embedded python Message-ID: <1312017883.11658.72.camel@cytherian> Hi! I want to create a python module in embedded python from string (The module script is stored in a database). My code looks like this: command.py: class Command: def execute(self): return "foo" main.cpp: #include #include #include int main(int argc, char **argv) { Py_Initialize(); try { // read the Command class std::stringstream buffer; std::ifstream ifile("command.py"); buffer << ifile.rdbuf(); ifile.close(); boost::python::str command_class(buffer.str()); // create module boost::python::object py_module_new = boost::python::import("new"); boost::python::object module = py_module_new.attr("module")("testmodule"); boost::python::object module_namespace = module.attr("__dict__"); // add Command class to the module boost::python::exec(command_class, module_namespace); // test Command boost::python::object command = module.attr("Command")(); boost::python::object r = command.attr("execute")(); std::string value = boost::python::extract(r); std::cout << value << std::endl; } catch(...) { PyErr_Print(); PyErr_Clear(); } Py_Finalize(); return 0; } It works as expected. But when I add and import command to the command.py file, it fails: command.py: import math class Command: def execute(self): return "foo" The error is: Traceback (most recent call last): File "", line 1, in ImportError: __import__ not found What am I missing? Thanks in advance: Imre Horvath From valentin.perrelle at orange.fr Sat Jul 30 22:15:28 2011 From: valentin.perrelle at orange.fr (Valentin Perrelle) Date: Sat, 30 Jul 2011 22:15:28 +0200 Subject: [C++-sig] Abstract class instances to-python conversion Message-ID: <4E346660.5020701@orange.fr> Hi, I'm currently embedding and extending Python using Boost.Python. I'm trying to expose some c++ library (OIS) classes to my Python scripts. This library mainly exposes abstract classes since the actual implementation are derived classes specialized for each operating system. So, i have to wrap those abstract classes. Then, eventually i will convert some existing C++ object of this class to its Python equivalent. Ideally, I would think that the HeldType is a pointer to the existing C++ object. There is no pointer managment problem since the lifetime of the object is greater than the execution time of the script. There is probably something i don't understand in the design of Boost.Python. At this point, my problem is that i need a to_python conversion which requires the abscence of noncopyable attribute which then implies to be able to build an instance of the object (which i cannot provide since the class is abstract, and i don't have any concrete derived class). I don't yet understand why holding a pointer in the Python object requires the ability to build instances of the wrapped class. The exact compile-time error i get is: boost_1_44/boost/python/object/pointer_holder.hpp:194:14: error: cannot allocate an object of abstract type 'OIS::Keyboard' I'm using boost 1.44 (required by some other library) Python 3.2 and MinGW/Msys. Module declaration: BOOST_PYTHON_MODULE(OIS) { class_("Keyboard", no_init); } Python init: try { PyImport_AppendInittab("OIS", PyInit_OIS); Py_InitializeEx(0); object main(import("__main__")); dict globals(main.attr("__dict__")); globals["keyboard"] = ptr(keyboard); } catch (error_already_set&) { PyErr_Print(); } Did i choose the wrong desing ? Did i do something wrong ? What should i do to solve this problem ? Valentin Perrelle. From talljimbo at gmail.com Sat Jul 30 23:47:45 2011 From: talljimbo at gmail.com (Jim Bosch) Date: Sat, 30 Jul 2011 14:47:45 -0700 Subject: [C++-sig] Abstract class instances to-python conversion In-Reply-To: <4E346660.5020701@orange.fr> References: <4E346660.5020701@orange.fr> Message-ID: <4E347C01.2010903@gmail.com> On 07/30/2011 01:15 PM, Valentin Perrelle wrote: > Hi, > > I'm currently embedding and extending Python using Boost.Python. I'm > trying to expose some c++ library (OIS) classes to my Python scripts. > This library mainly exposes abstract classes since the actual > implementation are derived classes specialized for each operating system. > > So, i have to wrap those abstract classes. Then, eventually i will > convert some existing C++ object of this class to its Python equivalent. > Ideally, I would think that the HeldType is a pointer to the existing > C++ object. There is no pointer managment problem since the lifetime of > the object is greater than the execution time of the script. > In this case, I don't you need to specify a HeldType, because that only affects what happens when you construct the object in Python, and you aren't every doing that. But you do need to specify "noncopyable" if the class doesn't have a copy constructor... > There is probably something i don't understand in the design of > Boost.Python. At this point, my problem is that i need a to_python > conversion which requires the abscence of noncopyable attribute which > then implies to be able to build an instance of the object (which i > cannot provide since the class is abstract, and i don't have any > concrete derived class). I don't yet understand why holding a pointer in > the Python object requires the ability to build instances of the wrapped > class. The exact compile-time error i get is: > > boost_1_44/boost/python/object/pointer_holder.hpp:194:14: error: cannot > allocate an object of abstract type 'OIS::Keyboard' > Why do you think you can't have noncopyable? You can certainly support some to-python conversions (including the one you've invoked below with "ptr(keyboard)") on a noncopyable class. Are you hoping to support some specific one, or is this the root of your misunderstanding? Anyhow, I'd recommend trying class_("Keyboard", no_init); with the rest of what you have. Good luck! Jim Bosch > > BOOST_PYTHON_MODULE(OIS) > { > class_("Keyboard", no_init); > } > > Python init: > > try { > PyImport_AppendInittab("OIS", PyInit_OIS); > Py_InitializeEx(0); > > object main(import("__main__")); > dict globals(main.attr("__dict__")); > globals["keyboard"] = ptr(keyboard); > } > catch (error_already_set&) { > PyErr_Print(); > } From valentin.perrelle at orange.fr Sun Jul 31 00:18:32 2011 From: valentin.perrelle at orange.fr (Valentin Perrelle) Date: Sun, 31 Jul 2011 00:18:32 +0200 Subject: [C++-sig] Abstract class instances to-python conversion In-Reply-To: <4E347C01.2010903@gmail.com> References: <4E346660.5020701@orange.fr> <4E347C01.2010903@gmail.com> Message-ID: <4E348338.6080708@orange.fr> Thank you for your answer. > Why do you think you can't have noncopyable? I understood it prevents the registration of converters for the class. I just read the manual again and now i understand it only remove converter which copy instances, i.e. conversion of values. > Anyhow, I'd recommend trying > > class_("Keyboard", no_init); > > with the rest of what you have. That's what I initially tried. It produced runtime error: TypeError: No Python class registered for C++ class OIS::Keyboard Thanks to you, I know understand some points i couldn't catch reading the manual 3-4 times. I'm now able to fix the current problem by importing my module before assigning the variable 'keyboard'. Which leads me to another question : is there a way to register converters without importing the module ? From talljimbo at gmail.com Sun Jul 31 07:38:50 2011 From: talljimbo at gmail.com (Jim Bosch) Date: Sat, 30 Jul 2011 22:38:50 -0700 Subject: [C++-sig] Abstract class instances to-python conversion In-Reply-To: <4E348338.6080708@orange.fr> References: <4E346660.5020701@orange.fr> <4E347C01.2010903@gmail.com> <4E348338.6080708@orange.fr> Message-ID: <4E34EA6A.9080800@gmail.com> On 07/30/2011 03:18 PM, Valentin Perrelle wrote: > Thanks to you, I know understand some points i couldn't catch reading > the manual 3-4 times. I'm now able to fix the current problem by > importing my module before assigning the variable 'keyboard'. Which > leads me to another question : is there a way to register converters > without importing the module ? > Hmm. That's a little tricky. You can of course put your "class_" definitions in an arbitrary C++ function, and call that somehow before importing the module, but then you really shouldn't call that function again when importing because that would register some bits of the class twice. I guess I don't really understand how your program flow is supposed to work - how did you plan to invoke C++ code from Python before importing your Boost.Python module? Usually the natural place to register converters is during module import after you've registered the classes. Jim From valentin.perrelle at orange.fr Sun Jul 31 09:52:00 2011 From: valentin.perrelle at orange.fr (Valentin Perrelle) Date: Sun, 31 Jul 2011 09:52:00 +0200 Subject: [C++-sig] Abstract class instances to-python conversion In-Reply-To: <4E34EA6A.9080800@gmail.com> References: <4E346660.5020701@orange.fr> <4E347C01.2010903@gmail.com> <4E348338.6080708@orange.fr> <4E34EA6A.9080800@gmail.com> Message-ID: <4E3509A0.9070901@orange.fr> Le 31/07/2011 07:38, Jim Bosch a ?crit : > I guess I don't really understand how your program flow is supposed to > work - how did you plan to invoke C++ code from Python before > importing your Boost.Python module? Usually the natural place to > register converters is during module import after you've registered > the classes. I don't plan to invoke c++ code from Python before importing the module: I need to import the module before exposing some instance of some class of the module. Does this mean that the module should be already imported when the script start running ? Can't i expose the object and then let decide the Python script wheter it need to use it or not ? Valentin Perrelle. From simwarg at gmail.com Sun Jul 31 23:08:14 2011 From: simwarg at gmail.com (Simon W) Date: Sun, 31 Jul 2011 23:08:14 +0200 Subject: [C++-sig] Wrap std::vector Message-ID: >From my research it seems not very trivial to wrap std::vector that holds pointer types. For example: std::vector I've looked at boost python vector_index_suite but it just gives me the runtime error: > TypeError: No to_python (by-value) converter found for C++ type: > GameObject* I have already exposed GameObject: class_(" GameObject") ... So it have come to my understanding it's not possible with an out of the box solution. I have to do some kind of wrapper? Could someone just help me out where I should start? Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: