How to wrap C structs in Cython for use in Python? -


For some learning experiences, I'm trying to wrap some parts of SDL (1.2.14) into Cython Python An extension for 3.2

I am having trouble directly converting strontact directly into Python, which is able to directly access its attributes like:

  struct_name. For example, I want to get struct SDL_Surface:  
  typed text SDL_Rect {Uint32 flags SDL_PixelFormat * format int w, h Uint16 pitch void * pixels SDL_chint clip_ect ER refcount} SDL_Rect;   

and be able to use it in Python:

  import SDL # to start the luggage screen = SDL.SetVideoMode (320, 480, 32, SDL .DOUBLEBUF) To access SDL_Surface.w and SDL_Surface.h print (screen.W, '', screen .h), now, I have wrapped the SDL_SetVideoMode and SDL_Surface in a way called a SDL HP file  
  cdf extern from 'sdl.h': # other stuff std SDL_Surface: unsigned long flags SDL_PixelFormat * format int w, h # like the previous declaration ... SDL_Surface * SDL_SetVideoMode (int, int , Int, inti Gned) cdef class Surface: # def Set video mode (width, height, BPP, flags) How to apply: cdef SDL_Surface * screen = SDL_SetVideoMode if the screen is not: err = SDL_GetError () Exception increment (error) # Return Possible way? ... Return page (screen)   

How should I use SDL? Surface? In a simple case, if the structure is opaque, it is as simple:

Foo.h "from cdef extern: struct spam: pass

When you want to reach members, there are several options, well presented in docs:



Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -