Re: Help wrapping SDL2.0

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

Close! The allocate_string() function actually accepts a string and pokes it into memory for you. Just use allocate_string() directly. You could use allocate() and poke_string() but that's just twice the work.

A few other points on this as well...

  • It doesn't look like you're free()-ing the values you've allocated. Always make sure to free anything you allocate.
  • You can also use automatic cleanup on any allocate function by adding a 1 as the second parameter.
  • Thanks to the magic of automatic cleanup, you can one-line the entire function call.
  • You can return the value from c_func() directly without storing it. Unless you need it for some reason.
  • Since you're using Euphoria 4.0, you should be using public, not global, which is generally discouraged (see Defining the scope of an identifier).
public constant SDL_HINT_WINRT_HANDLE_BACK_BUTTON  = "SDL_HINT_WINRT_HANDLE_BACK_BUTTON" 
 
-- I have already opened the SDL in another header so I have this 
 
constant xSDL_SetHint = define_c_func( sdl, "SDL_SetHint", {C_POINTER, C_POINTER}, C_BOOL) 
 
public function SDL_SetHint( sequence name, sequence value ) 
 
    -- allocate the strings into memory with automatic cleanup 
    atom p_name = allocate_string( name, 1 ) 
    atom p_value = allocate_string( value, 1 ) 
 
    -- don't bother storing the return value, 
    -- just return whatever c_func() gives us 
    return c_func( xSDL_SetHint, {p_name,p_value} ) 
end function 
 
-- Thanks to automatic cleanup, you can also one-line this whole function call... 
 
public function SDL_SetHint( sequence name, sequence value ) 
    return c_func( xSDL_SetHint, {allocate_string(name,1),allocate_string(value,1)} ) 
end function 

Hope that helps,

-Greg

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

Search



Quick Links

User menu

Not signed in.

Misc Menu