Why wasn't the binding using Compact class?
Yu
On Sun, Nov 8, 2009 at 9:47 AM, Frederik <[email protected]> wrote:
> aaron andersen wrote:
> > Is there a list of all the available tags for the vala parser? Like
> > [array_length], [array_null_terminated], [NoArrayLength], etc...
>
> Unfortunately, there is no such list. [NoArrayLength] is deprecated in
> favor
> of [CCode (array_length=false)].
>
> > I'm trying to figure out how to get the function SDL_ListModes to bind
> > properly but am at a bit of a loss.
> >
> > struct SDL_Rect is defined in the vapi as a struct (Rect) and
> > SDL_ListModes returns a null terminated array of pointers to SDL_Rect
> > structs...
> >
> > SDL_Rect **modes = SDL_ListModes(params...);
> > int i = 0;
> > while ((SDL_Rect *iterator = modes[i]) != NULL) {
> > i++
> > }
> >
> > Given that the current bindings for SDL just returns a void * I'm not
> > even sure this is possible with vala?
> >
> > Any help greatly appreciated!
> >
>
> This is the correct binding:
>
> [CCode (cname="SDL_ListModes", array_length=false,
> array_null_terminated=true)]
> public static unowned Rect*[]? list_modes(PixelFormat? format, uint32
> flags);
>
> Explanation:
>
> http://sdl.beuc.net/sdl.wiki/SDL_ListModes
> "Return Value: The pointer to the array of SDL_Rect
> On success. The pointer to the video dimensions array is managed by SDL
> itself. The caller must not free the returned pointer."
>
> * The last sentence means 'unowned'
> * '[]' because it is an array
> * '?' because it can return 'null'
> * The function doesn't have a length out parameter, this means no array
> length
> * The code example 'for (i=0; modes[i]; ++i)' indicates that it is 'null'
> terminated instead
>
> Unfortunately, the returned array is somewhat odd because it is an array of
> pointers to structs instead of a simple array of structs. Vala expects that
> only for arrays of heap-allocated objects but not for struct arrays. That's
> why you need to add a '*' and have to access the 'w' and 'h' fields of the
> 'Rect's with '->' in this example program:
>
>
> ----------------------------------------------------------------------------
> using SDL;
>
> int main () {
> SDL.init (InitFlag.VIDEO);
>
> var modes = Video.list_modes (null, SurfaceFlag.FULLSCREEN
> | SurfaceFlag.HWSURFACE);
> if (modes == null) {
> stderr.printf ("No modes available!\n");
> return 1;
> }
> if ((int) modes == -1) {
> stderr.printf ("All resolutions available.\n");
> return 1;
> }
>
> foreach (var mode in modes) {
> stdout.printf ("%d x %d\n", mode->w, mode->h);
> }
>
> SDL.quit ();
>
> return 0;
> }
>
> ----------------------------------------------------------------------------
>
>
> Best regards,
>
> Frederik
> _______________________________________________
> Vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
>
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list