How to represent C pointer the best?

25 Views Asked by At

In C function we have

SDL_Surface * SDL_GetWindowSurface(SDL_Window *window);

In LoStanza interface, this is what I have done to make it work.

lostanza defn call-SDL_GetWindowSurface (p : ref<Long>) -> ref<Long> :
   val ws = call-c SDL_GetWindowSurface(p.value)
   return new Long{ws}

Note that ref is used as return type to preserve the value of pointer to an SDL_Surface. Also, p : ref is storing the value of the pointer to SDL_Window.

These pointers are not used in Stanza code. They are just kept as handles so that they can be passed around in the next calls to SDL.

Is this approach correct? I feel using Long is not entirely correct. But when ptr<?> is used, there is no Stanza type it can take reference to.

0

There are 0 best solutions below