New filters on the Home Feed, take a look!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Overriding C++ class in Python (Boost.Python)
Post Body

I've got a ton of C code that I am converting to Python. I'm using Boost.Python until all the C code is gone (I looked at PyBind11, but one of my deployed environments is on gcc 4.7).

I've got the main C class (Game), and an interposer for talking to Python (Atlantis). I then derive a sub-class PyAtlantis:

class PyAtlantis : public Atlantis, public boost::python::wrapper<Atlantis>

I forward all the methods from Atlantis, using:

get_override("fun_name")(args)

That compiles, but at run time I get:

Traceback (most recent call last):
  File "../../atlantis.py", line 43, in <module>
    game.enableItem("sword")
Boost.Python.ArgumentError: Python argument types in
    PyAtlantis.enableItem(CAtlantis, str)
did not match C   signature:
    enableItem(PyAtlantis {lvalue}, std::string, bool)
    enableItem(PyAtlantis {lvalue}, std::string)

This is the same error I was getting when I just tried to override the functions without the wrapper...

The Python code is:

class CAtlantis(Atlantis.PyAtlantis):
    def __init__(self):
        pass

game = CAtlantis()
game.enableItem("sword")

The code is https://github.com/nedbrek/Atlantis/tree/PyAtlantis although I haven't pushed this patch yet...

Author
Account Strength
100%
Account Age
14 years
Verified Email
Yes
Verified Flair
No
Total Karma
5,923
Link Karma
921
Comment Karma
5,002
Profile updated: 1 day ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
7 years ago