2014-12-02 94 views
1

我试图在RubyMotion中使用giflib C库。它在供应商文件夹中编译得很好。但我还是不能确定在Ruby的C结构的访问:从RubyMotion访问C结构

error = Pointer.new(:int) 
pointer = DGifOpenFileName("foobar.gif", error) # returns (GifFileType *) 

的C结构:

typedef struct GifFileType { 
    GifWord SWidth, SHeight; 
    // ... 
    ColorMapObject *SColorMap; 
    // ... 
} GifFileType; 

访问红宝石指针生成运行时错误:

puts pointer.value # => Can't find pointer description for type `{ColorMapObject}' 

我是什么做错了?

(以下是完整gif_lib.h和生成的giflib.bridgesupport。)

回答

0

你在做什么似乎像它应该工作。我会用motion support提交报告。

RubyMotion Runtime Guide指示如下内容:

C structures are mapped to classes in RubyMotion. Structures can be created in Ruby and passed to APIs expecting C structures. Similarly, APIs returning C structures will return an instance of the appropriate structure class. A structure class has an accessor method for each field of the C structure it wraps. As an example, the following piece of code creates a CGPoint structure, sets its x and y fields, then passes it to the drawAtPoint:withFont: method.

pt = CGPoint.new 
pt.x = 100 
pt.y = 200 
'Hello'.drawAtPoint(pt, withFont: font) 

It is possible to pass the field values directly to the constructor.

pt = CGPoint.new(100, 200) 
'Hello'.drawAtPoint(pt, withFont: font) 

RubyMotion will also accept arrays as a convenience. They must contain the same number and type of objects expected in the structure.

'Hello'.drawAtPoint([100, 200], withFont: font)