You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello!
I have made a module that uses the SDL2 library on the C++ side, and I chose to use PySDL2 to provide some existing bindings on the Python side (as manually writing all of them was out of the scope of my project).
I am currently using this workaround, which works:
classPyEventListener : publicEventListener {
public:using EventListener::EventListener;
boolhandleEvent(SDL_Event& sdl_event) override {
PYBIND11_OVERRIDE(bool, EventListener, handleEvent, sdl_event);
}
};
PYBIND11_MODULE(module, m) {
// Exposing SDL_Event as a buffer so that it can be used as a sdl2.SDL_Event in python (from pysdl2)
py::class_<SDL_Event>(m, "SDL_Event", py::buffer_protocol())
.def_buffer([](SDL_Event& event) -> py::buffer_info {
returnpy::buffer_info(
(Uint8*)&event,
sizeof(Uint8),
py::format_descriptor<Uint8>::format(),
1,
{ 56 },
{ sizeof(Uint8) }
);
})
py::class_<EventListener, std::shared_ptr<EventListener>, PyEventListener>(m, "EventListener")
.def(py::init());
}
My question is whether there could be a way to somehow bind the C struct SDL_Event to the existing python struct sdl2.SDL_Event so that in the above code the parameter event would be of type sdl2.SDL_Event instead of module.SDL_Event (which then requires the manual conversion).
This would be also useful the other way around as for now my only lead is to use implicit conversions between sdl2.SDL_Event and module.SDL_Event, which seems convoluted not having access to sdl2.SDL_Event from my C++ module.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
I have made a module that uses the SDL2 library on the C++ side, and I chose to use PySDL2 to provide some existing bindings on the Python side (as manually writing all of them was out of the scope of my project).
I am currently using this workaround, which works:
And on the Python side I have to use this:
My question is whether there could be a way to somehow bind the C struct
SDL_Event
to the existing python structsdl2.SDL_Event
so that in the above code the parameterevent
would be of typesdl2.SDL_Event
instead ofmodule.SDL_Event
(which then requires the manual conversion).This would be also useful the other way around as for now my only lead is to use implicit conversions between
sdl2.SDL_Event
andmodule.SDL_Event
, which seems convoluted not having access tosdl2.SDL_Event
from my C++ module.Beta Was this translation helpful? Give feedback.
All reactions