Re: [C++-sig] Abstract class instances to-python conversion

2011-08-01 Thread Valentin Perrelle
All of that sounds sounds. But at what point were you trying to register a to-python converter? It sounded like you were trying to do that before importing the module, and since a to-python converter is by definition C++, I didn't understand how you could do it in a Python script before imp

Re: [C++-sig] Abstract class instances to-python conversion

2011-08-01 Thread Simon Warg
You could use the reload() function in python 2.7 or imp.reload() in python 3. It takes a module object as argument. // Simon On 1 aug 2011, at 12:00, Valentin Perrelle wrote: > >> All of that sounds sounds. But at what point were you trying to register a >> to-python converter? It sounded

Re: [C++-sig] Abstract class instances to-python conversion

2011-08-01 Thread Valentin Perrelle
You could use the reload() function in python 2.7 or imp.reload() in python 3. It takes a module object as argument. Thanks. However it wouldn't reset to the initial state in the general case. All modules needs to be unloaded. I don't know a safe way to it yet. I'm just sure i want to do it i

Re: [C++-sig] Abstract class instances to-python conversion

2011-08-01 Thread Simon Warg
In My program I need to unload modules as well. What I do is remove all references to the particular module and it will be unloaded. Are you using boost python for python 2 or 3? If it's the latter it is safe to use Py_Finalize()! I use it myself! // Simon On 1 aug 2011, at 12:58, Valentin Per

Re: [C++-sig] Abstract class instances to-python conversion

2011-08-01 Thread Valentin Perrelle
Le 01/08/2011 13:19, Simon Warg a écrit : In My program I need to unload modules as well. What I do is remove all references to the particular module and it will be unloaded. It seems i didn't achieve to do that. There should be some references i can't remove, i don't know why yet. Are you

Re: [C++-sig] Abstract class instances to-python conversion

2011-08-01 Thread Simon Warg
You can remove one reference from the sys module: Import sys del sys.modules['mymodule'] In cpp it would be like: import('sys').attr('modules')['mymodule'].del() I can give you my code later. Don't have it here! // Simon On 1 aug 2011, at 13:38, Valentin Perrelle wrote: > Le 01/08/2011 13:19

[C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread diego_pmc
I have an `EventManager` class written in C++ and exposed to Python. This is how I intended for it to be used from the Python side: class Something: def __init__(self): EventManager.addEventHandler(FooEvent, self.onFooEvent) def __del__(self): EventManag

Re: [C++-sig] Wrap std::vector

2011-08-01 Thread diego_pmc
You don't really provide that much information: you want help with writing a wrapper? do you want C++ and Python to point to the same instance of `GameObject`? If it's the latter, have you tried doing `vector>`? -- View this message in context: http://boost.2283326.n

Re: [C++-sig] Wrap std::vector

2011-08-01 Thread Simon W
I wrap my c++ vector like: class_("GameObjectList") .def(vector_index_suite); When I run the following in python: objects = gameobject_manager.getGameObjects() # getGameObjects is returning a std::vector for object in objects: ... I get the error > TypeError: No to_python (by-value) converter

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Nat Goodspeed
On Aug 1, 2011, at 10:50 AM, diego_pmc wrote: > How should I capture Python function objects such > that I won't increase their reference count? I only need a weak reference to > the objects. http://docs.python.org/library/weakref.html#module-weakref I don't know how to access a Python weakref

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Jim Bosch
On 08/01/2011 07:50 AM, diego_pmc wrote: I have an `EventManager` class written in C++ and exposed to Python. This is how I intended for it to be used from the Python side: class Something: def __init__(self): EventManager.addEventHandler(FooEvent, self.onFooEvent)

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread diego_pmc
On Tue, Aug 2, 2011 at 3:00 AM, Nat Goodspeed wrote: > > > http://docs.python.org/library/weakref.html#module-weakref > > Unfortunately, I can't use `weakref` I already tried that, but the problem is that the weak references get deleted (and their value set to `None`) before `__del__` is called. S

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Jim Bosch
On 08/01/2011 09:44 PM, diego_pmc wrote: Are these cycles actually a problem in practice? Python does do garbage collection, so it might be that it knows about all these dependencies and just hasn't bothered to try to delete them because it doesn't need the memory yet. Y

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Paul-Cristian Manta
On Tue, Aug 2, 2011 at 8:24 AM, Jim Bosch wrote: > > Hmm. That might mean you need to do a big design change; while it often > works, one really isn't supposed to rely on __del__ being called when a > Python object first could be garbage-collected - when cycles are involved, > Python doesn't eve