Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Functions returning structures
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
galdor  
View profile  
 More options Dec 14 2009, 4:29 pm
From: galdor <khae...@gmail.com>
Date: Mon, 14 Dec 2009 13:29:55 -0800 (PST)
Local: Mon, Dec 14 2009 4:29 pm
Subject: Functions returning structures
Hi,

Let's define a C function which returns a plain structure:

    typedef struct {
        int r, g, b, a;
    } ALLEGRO_COLOR;

    ALLEGRO_COLOR al_map_rgb(unsigned char r, unsigned char g,
unsigned char b);

Now we bind it:

    class ALLEGRO_COLOR < FFI::Struct
        layout :r, :float,
               :g, :float,
               :b, :float,
               :a, :float
    end

    attach_function :al_map_rgb, [:uchar, :uchar, :uchar],
ALLEGRO_COLOR

But the following ruby code doesn't work:

    bgcolor = al_map_rgb(20, 20, 20)
    fgcolor = al_map_rgb(20, 40, 80)
    al_clear_to_color(bgcolor)

The screen is cleared with rgb(20, 40, 80), instead of rgb(20, 20,
20).
I don't know how stack allocation is performed, I must be doing
something wrong.

How should I work with stack-allocated structures ?

Regards,

Nicolas Martyanoff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wayne Meissner  
View profile  
 More options Dec 14 2009, 4:33 pm
From: Wayne Meissner <wmeiss...@gmail.com>
Date: Tue, 15 Dec 2009 07:33:22 +1000
Local: Mon, Dec 14 2009 4:33 pm
Subject: Re: [ruby-ffi] Functions returning structures
You need to specify the return type as ALLEGRO_COLOR.by_value
(same for any struct-by-value parameters).

2009/12/15 galdor <khae...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
galdor  
View profile  
 More options Dec 14 2009, 4:42 pm
From: galdor <khae...@gmail.com>
Date: Mon, 14 Dec 2009 13:42:47 -0800 (PST)
Local: Mon, Dec 14 2009 4:42 pm
Subject: Re: Functions returning structures

Thank you, it just works!
I also had to use .by_value for parameters, of course.

I'll notify the author of ffi-swig-generator about this, its tool
doesn't produce these annotations.

Regards,

Nicolas Martyanoff

On Dec 14, 10:33 pm, Wayne Meissner <wmeiss...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »