Subject:
Re: [ruby-ffi] Describing an anonymous union
From:
Wayne Meissner
Date:
10/13/13 7:43 PM
To:
ruby-ffi@googlegroups.com

Yep, that should work.  Can even leave off the class_eval - 

Class.new(FFI::Union) do
  layout :msg, :pointer, 
            :song_end, UadeNotificationSongEnd
end

The only things that won't work are typedefs/aliases - they use a hacky way to find the enclosing module (which contains the typedef table), which won't work with anon classes.

Lexically scoped things will work fine though (and the built in FFI types)

On Sunday, 13 October 2013 10:23:08 UTC+11, Postmodern wrote:

Usually I just come up with some name for anonymous structs/unions. However, I wonder if you could do

layout :type, :uade_notification_type,
       :union, Class.new(FFI::Union).class_eval do
                 ...
               end

or something similar?

On 10/12/2013 04:44 AM, Misty De Meo wrote:

How can I represent an anonymous union in FFI?

A struct I'm wrapping has the following structure:

struct uade_notification {
    enum uade_notification_type type;
    union {
        char *msg;
        struct uade_notification_song_end song_end;
    };
};

I can create a union using FFI::Union of course, but I'm not sure how to represent that in a struct layout. Is assigning it an arbitrary name the right way to go?

Best,
Misty
--
 
---
You received this message because you are subscribed to the Google Groups "ruby-ffi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-ffi+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

-- 
Blog: http://postmodern.github.com/
GitHub: https://github.com/postmodern
Twitter: @postmodern_mod3
PGP: 0xB9515E77

--
 
---
You received this message because you are subscribed to the Google Groups "ruby-ffi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-ffi+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.