2014-12-02 4 views
1

RubyMotion에서 giflib C 라이브러리를 사용하려고합니다. 그것은 벤더 폴더에서 잘 컴파일됩니다.RubyMotion에서 C 구조체에 액세스

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

는 C 구조체 :

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

어떻게 생각 : 루비 포인터를 액세스

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

런타임 오류가 발생하지만 난 여전히 루비에서 C 구조체 액세스에 대한 확실 해요 잘못하고있는거야?

(여기에. 전체 gif_lib.h 및 생성 된 giflib.bridgesupport 있습니다)가 작동해야처럼

답변

0

은 당신이하는 일은 같다. motion support으로 신고 해 드리겠습니다.

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) 
:

RubyMotion Runtime Guide 다음과 같은 표시