Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97049 > unrolled thread

Sending a python argument to a Boost.Python function

Started bykenseehart@gmail.com
First post2015-09-23 12:02 -0700
Last post2015-09-24 15:16 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Sending a python argument to a Boost.Python function kenseehart@gmail.com - 2015-09-23 12:02 -0700
    Re: Sending a python argument to a Boost.Python function Laura Creighton <lac@openend.se> - 2015-09-24 15:16 +0200

#97049 — Sending a python argument to a Boost.Python function

Fromkenseehart@gmail.com
Date2015-09-23 12:02 -0700
SubjectSending a python argument to a Boost.Python function
Message-ID<bbff707d-09b1-4123-9d9c-1d17dff2258c@googlegroups.com>
I have a python class that wraps a boost.python object. I am using a boost.python library function that requires the raw boost.python object. I want to be able to pass the python object to the boost api function.

Is there a hook available on the python side that instructs boost to perform a conversion?

Hypothetically, it would be something like this:

class EggWrapper(object):
    def __init__(self, egg):
        object.__setattr__(self, '_egg', egg)

    def __getattribute__(self, name):
        egg = object.__getattribute__(self, '_egg')

        if name=='_egg':
            return egg

        if name in EggWrapper.__dict__:
            return object.__getattribute__(self, name)

        return getattr(egg, name)

    def __setattr__(self, name, value):
        egg = object.__getattribute__(self, '_egg')
        setattr(egg, name, value)

    def magic_boost_conversion_unicorn_hook(self):
        'this is automatically called by boost to convert arguments'
        egg = object.__getattribute__(self, '_egg')
        return egg
        

import myboostlib

egg = EggWrapper(myboostlib.getEgg())

myboostlib.spam(egg)


Where the signature for spam is: spam(class boost::python::api::object)
And myboostlib.getEgg() returns a boost::python::api::object

- I do not have the ability to modify the library or any C/C++ code, the solution must be entirely on the python side.

- I can't change the calling convention. The wrapped object must be used (i.e. I can't just say myboostlib.spam(egg._egg), though that is the desired result). So the solution should be incorporated into the EggWrapper class.

- I'm only interested in solutions that reflect expert knowledge of Boost.Python, since I believe I have already considered all the trivial solutions.

So my question is, does magic_boost_conversion_unicorn_hook() exist, and if so, how is it spelled?


Thanks,
~ Ken




[toc] | [next] | [standalone]


#97071

FromLaura Creighton <lac@openend.se>
Date2015-09-24 15:16 +0200
Message-ID<mailman.124.1443100616.28679.python-list@python.org>
In reply to#97049
Try that question here:
https://mail.python.org/mailman/listinfo/cplusplus-sig

Laura

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web