Re: FFI Wrapping Help

new topic     » goto parent     » topic index » view thread      » older message » newer message
ChrisB said...
Icy_Viking said...

Hello all,

I am wondering how you would wrap this with the FFI library.

typedef struct SDL_GameControllerButtonBind 
{ 
    SDL_GameControllerBindType bindType; 
    union 
    { 
        int button; 
        int axis; 
        struct { 
            int hat; 
            int hat_mask; 
        } hat; 
    } value; 
 
} SDL_GameControllerButtonBind; 

I know with unions you can't exactly wrap them as you would with a normal struct.

My idea is

export constant SDL_GAMECONTROLLERBUTTONID = define_c_type({ 
  C_INT --button 
  C_INT --axis 
  C_POINTER --for struct 
  C_INT --hat 
  C_INT --hat_mask 
}) 

And yes, that looks exactly right - you can flatten out the 'single layer' structures within unions, as th memory is accessible n the same way - they are read into (in our cases) sequences or variables before use any way.

Cheers

Chris

Thanks Chris. Yeah that Joystick code is still good. I'll have to wait and see what and if there are any major changes when SDL 3 is released.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu